Skip to content
This repository has been archived by the owner on Nov 12, 2021. It is now read-only.

Commit

Permalink
Merge pull request #3 from j01tz/framing
Browse files Browse the repository at this point in the history
Framing alignment
  • Loading branch information
j01tz authored Apr 14, 2020
2 parents e8949bb + 0ed3b9b commit 66f138e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "slatepack"
version = "0.1.3"
version = "0.2.0"
authors = ["j01tz"]
edition = "2018"

Expand Down
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ println!("{}", armor);
use std::fs::File;
use std::io::Write;
...
let armor_response = "BEGIN SLATEPACK...END SLATEPACK.".to_string();
let armor_response = "BEGINSLATEPACK...ENDSLATEPACK.".to_string();
let response_slate = slatepack::remove_armor(armor_response).unwrap();
let mut response_file = File::create("test.tx.response").unwrap();
response_file.write_all(response_slate.as_bytes()).unwrap();
Expand All @@ -41,7 +41,7 @@ use slatepack;
use std::fs::File;
use std::io::Write;
...
let armor = "BEGIN SLATEPACK...END SLATEPACK.".to_string();
let armor = "BEGINSLATEPACK...ENDSLATEPACK.".to_string();
let slate = slatepack::remove_armor(&armor).unwrap();
let mut slate_file = File::create("test.tx").unwrap();
slate_file.write_all(slate.as_bytes()).unwrap();
Expand Down Expand Up @@ -86,7 +86,7 @@ println!("{}", armor);

#### V4 initial slate armored with slatepack:
```
BEGIN SLATEPACK. 2xfX9bS82gxJ6jN D6X4X843wrT84DT FkstYawTtacDqeU HybZLwcF26YXCix bmpTcw3hii6BF4x axfussSBrZq7xMQ P1rbw3GpebXkMeY i7aSjRZgxqDJwzt MyGqBauGHxEFZNg FeEbVFsqXaKkKwK PQdxrpKutVmJV67 pbY4nbeZgPtRaZj QZL61Wj7iGqKBuu tDvEwUBsuhb9GRf 1MK3jegnbKG5JJr QVrYignWoZrpXUx PiDobVMLh7RTRrz T6GNKJftiwJ5gup f7T69mFG9H8JqCG A4i5ogfcHhfgg5b 2AzBJA49nh39Pyh zotpGBj7a7RK4Kr bWqksP7iTxvfdUB zVwinrRjLeryvF7 uroTKm514ZDDrKf ZbyncaZXcFGYHWM tWp5ccsjjtM1JqB adragavjHQyjqkU 2JH9YnoRkx2AyuU qvn7nnb4fMTAVSw sbAPwBTua7njNht nhzRqtdHTr9KM9q eXHDN9iascu. END SLATEPACK.
BEGINSLATEPACK. 2xfX9bS82gxJ6jN D6X4X843wrT84DT FkstYawTtacDqeU HybZLwcF26YXCix bmpTcw3hii6BF4x axfussSBrZq7xMQ P1rbw3GpebXkMeY i7aSjRZgxqDJwzt MyGqBauGHxEFZNg FeEbVFsqXaKkKwK PQdxrpKutVmJV67 pbY4nbeZgPtRaZj QZL61Wj7iGqKBuu tDvEwUBsuhb9GRf 1MK3jegnbKG5JJr QVrYignWoZrpXUx PiDobVMLh7RTRrz T6GNKJftiwJ5gup f7T69mFG9H8JqCG A4i5ogfcHhfgg5b 2AzBJA49nh39Pyh zotpGBj7a7RK4Kr bWqksP7iTxvfdUB zVwinrRjLeryvF7 uroTKm514ZDDrKf ZbyncaZXcFGYHWM tWp5ccsjjtM1JqB adragavjHQyjqkU 2JH9YnoRkx2AyuU qvn7nnb4fMTAVSw sbAPwBTua7njNht nhzRqtdHTr9KM9q eXHDN9iascu. ENDSLATEPACK.
```

### Example use:
Expand Down Expand Up @@ -129,7 +129,6 @@ assert_eq!(slate, json_slate);

### TODO
- [ ] Add support for multiple slatepack messages for very big slates
- [ ] Add slate type to framing for human convenience: INITIAL, RESPONSE, INVOICE
- [ ] Make more idiomatic

This should not be used for any real transactions. It is for educational purposes to visualize and experiment with the armored slate string format.
18 changes: 6 additions & 12 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,15 @@ use std::str;
extern crate lazy_static;

// Framing and formatting for slate armor
static HEADER: &str = "BEGIN SLATEPACK. ";
static FOOTER: &str = ". END SLATEPACK.";
static HEADER: &str = "BEGINSLATEPACK. ";
static FOOTER: &str = ". ENDSLATEPACK.";
const WORD_LENGTH: usize = 15;

lazy_static! {
static ref HEADER_REGEX: Regex = Regex::new(concat!(
r"^[>\n\r\t ]*BEGIN[>\n\r\t ]+([a-zA-Z0-9]+[>\n\r\t ]+)",
r"?SLATEPACK[>\n\r\t ]*$"
))
.unwrap();
static ref FOOTER_REGEX: Regex = Regex::new(concat!(
r"^[>\n\r\t ]*END[>\n\r\t ]+([a-zA-Z0-9]+[>\n\r\t ]+)",
r"?SLATEPACK[>\n\r\t ]*$"
))
.unwrap();
static ref HEADER_REGEX: Regex =
Regex::new(concat!(r"^[>\n\r\t ]*BEGINSLATEPACK[>\n\r\t ]*$")).unwrap();
static ref FOOTER_REGEX: Regex =
Regex::new(concat!(r"^[>\n\r\t ]*ENDSLATEPACK[>\n\r\t ]*$")).unwrap();
static ref WHITESPACE_LIST: [u8; 5] = [b'>', b'\n', b'\r', b'\t', b' '];
}

Expand Down

0 comments on commit 66f138e

Please sign in to comment.