From 8c4d2dbd9378aa94e8bd54b7f6a626a6bbc218b2 Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Fri, 18 Nov 2022 00:01:23 +0100 Subject: [PATCH] Fix tabs in comments --- src/enc/mod.rs | 16 ++++++------- src/lib.rs | 64 +++++++++++++++++++++++++------------------------- 2 files changed, 40 insertions(+), 40 deletions(-) diff --git a/src/enc/mod.rs b/src/enc/mod.rs index 9aa29e7..ef8e563 100644 --- a/src/enc/mod.rs +++ b/src/enc/mod.rs @@ -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>>(terms: I) -> Term<'a> { let mut tmp = Vec::with_capacity(8); @@ -96,9 +96,9 @@ pub fn list<'a, I: IntoIterator>>(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)>>(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, Error> { +pub fn encode(t: Term<'_>) -> Result, Error> { let mut buf = Vec::with_capacity(128); encode_aux(&mut buf, t.0, 0)?; Ok(buf) } -fn encode_aux<'a>(buf: &mut Vec, term: T<'a>, indent: usize) -> Result<(), Error> { +fn encode_aux(buf: &mut Vec, term: T<'_>, indent: usize) -> Result<(), Error> { match term { T::Str(s) => buf.extend_from_slice(s), T::OwnedStr(s) => buf.extend_from_slice(&s), diff --git a/src/lib.rs b/src/lib.rs index d42c8ac..95c375c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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: