Fix tabs in comments

This commit is contained in:
Alex 2022-11-18 00:01:23 +01:00
parent bf988bec2f
commit 8c4d2dbd93
Signed by: lx
GPG Key ID: 0E496D15096376BE
2 changed files with 40 additions and 40 deletions

View File

@ -75,9 +75,9 @@ pub fn raw(bytes: &[u8]) -> Term<'_> {
/// use nettext::enc::*;
///
/// assert_eq!(encode(list([
/// string("Hello"),
/// string("world")
/// ])).unwrap(), b"Hello world");
/// string("Hello"),
/// string("world")
/// ])).unwrap(), b"Hello world");
/// ```
pub fn list<'a, I: IntoIterator<Item = Term<'a>>>(terms: I) -> Term<'a> {
let mut tmp = Vec::with_capacity(8);
@ -96,9 +96,9 @@ pub fn list<'a, I: IntoIterator<Item = Term<'a>>>(terms: I) -> Term<'a> {
/// use nettext::enc::*;
///
/// assert_eq!(encode(dict([
/// ("a", string("Hello")),
/// ("b", string("world"))
/// ])).unwrap(), b"{\n a = Hello,\n b = world,\n}");
/// ("a", string("Hello")),
/// ("b", string("world"))
/// ])).unwrap(), b"{\n a = Hello,\n b = world,\n}");
/// ```
pub fn dict<'a, I: IntoIterator<Item = (&'a str, Term<'a>)>>(pairs: I) -> Term<'a> {
let mut tmp = HashMap::new();
@ -164,13 +164,13 @@ impl<'a> Term<'a> {
// ---- encoding function ----
/// Generate the nettext representation of a term
pub fn encode<'a>(t: Term<'a>) -> Result<Vec<u8>, Error> {
pub fn encode(t: Term<'_>) -> Result<Vec<u8>, Error> {
let mut buf = Vec::with_capacity(128);
encode_aux(&mut buf, t.0, 0)?;
Ok(buf)
}
fn encode_aux<'a>(buf: &mut Vec<u8>, term: T<'a>, indent: usize) -> Result<(), Error> {
fn encode_aux(buf: &mut Vec<u8>, term: T<'_>, indent: usize) -> Result<(), Error> {
match term {
T::Str(s) => buf.extend_from_slice(s),
T::OwnedStr(s) => buf.extend_from_slice(&s),

View File

@ -3,49 +3,49 @@
//! ```
//! use nettext::enc::*;
//! use nettext::dec::*;
//! use nettext::crypto::{self, Signer, Verifier};
//! use nettext::crypto::{self, Signer, Verifier};
//!
//! let keypair = crypto::generate_keypair();
//! let keypair = crypto::generate_keypair();
//!
//! // Encode a fist object that represents a payload that will be hashed and signed
//! let text1 = encode(list([
//! string("CALL"),
//! string("myfunction"),
//! dict([
//! ("a", string("hello")),
//! ("b", string("world")),
//! ("c", raw(b"{ a = 12, b = 42 }")),
//! ]),
//! keypair.public.term(),
//! ])).unwrap();
//! eprintln!("{}", std::str::from_utf8(&text1).unwrap());
//! string("CALL"),
//! string("myfunction"),
//! dict([
//! ("a", string("hello")),
//! ("b", string("world")),
//! ("c", raw(b"{ a = 12, b = 42 }")),
//! ]),
//! keypair.public.term(),
//! ])).unwrap();
//! eprintln!("{}", std::str::from_utf8(&text1).unwrap());
//!
//! let hash = crypto::Blake2Sum::compute(&text1);
//! let sign = keypair.sign(&text1);
//! let hash = crypto::Blake2Sum::compute(&text1);
//! let sign = keypair.sign(&text1);
//!
//! // Encode a second object that represents the signed and hashed payload
//! let text2 = encode(dict([
//! ("hash", hash.term()),
//! ("signature", sign.term()),
//! ("payload", raw(&text1)),
//! ])).unwrap();
//! eprintln!("{}", std::str::from_utf8(&text2).unwrap());
//! let text2 = encode(dict([
//! ("hash", hash.term()),
//! ("signature", sign.term()),
//! ("payload", raw(&text1)),
//! ])).unwrap();
//! eprintln!("{}", std::str::from_utf8(&text2).unwrap());
//!
//! // Decode and check everything is fine
//! let object1 = decode(&text2).unwrap();
//! let [hash, signature, payload] = object1.dict_of(["hash", "signature", "payload"], false).unwrap();
//! assert!(hash.b2sum().unwrap().verify(payload.raw()).is_ok());
//! assert_eq!(payload.raw(), text1);
//! // Decode and check everything is fine
//! let object1 = decode(&text2).unwrap();
//! let [hash, signature, payload] = object1.dict_of(["hash", "signature", "payload"], false).unwrap();
//! assert!(hash.b2sum().unwrap().verify(payload.raw()).is_ok());
//! assert_eq!(payload.raw(), text1);
//!
//! let object2 = decode(payload.raw()).unwrap();
//! let object2 = decode(payload.raw()).unwrap();
//!
//! let [verb, arg1, arg2, pubkey] = object2.list_of().unwrap();
//! let pubkey = pubkey.public_key().unwrap();
//! assert!(pubkey.verify(payload.raw(), &signature.signature().unwrap()).is_ok());
//! let [verb, arg1, arg2, pubkey] = object2.list_of().unwrap();
//! let pubkey = pubkey.public_key().unwrap();
//! assert!(pubkey.verify(payload.raw(), &signature.signature().unwrap()).is_ok());
//!
//! assert_eq!(verb.string().unwrap(), "CALL");
//! assert_eq!(arg1.string().unwrap(), "myfunction");
//! assert_eq!(pubkey, keypair.public);
//! assert_eq!(verb.string().unwrap(), "CALL");
//! assert_eq!(arg1.string().unwrap(), "myfunction");
//! assert_eq!(pubkey, keypair.public);
//! ```
//!
//! The value of `text1` would be as follows: