1 # tesid: Rust crate for Textualised Encrypted Sequential Identifiers
3 This crate implements the TESID scheme for producing short, human-friendly,
4 cryptographically-secure pseudorandom strings out of sequential identifiers.
6 See <https://chrismorgan.info/tesid/> for more information about TESID.
8 A simple demonstration:
11 let secret_key = "000102030405060708090a0b0c0d0e0f";
12 let coder = tesid::TesidCoder::new(secret_key).unwrap();
13 assert_eq!(&*coder.encode(0), "w2ej");
14 assert_eq!(&*coder.encode(1), "w6um");
15 assert_eq!(&*coder.encode(2), "x45g");
16 assert_eq!(&*coder.encode(2_u64.pow(20) - 1), "atcw");
17 assert_eq!(&*coder.encode(2_u64.pow(20)), "8qwm6y");
18 assert_eq!(&*coder.encode(2_u64.pow(30) - 1), "3eipc7");
19 assert_eq!(&*coder.encode(2_u64.pow(30)), "n3md95r4");
20 assert_eq!(&*coder.encode_long(2_u128.pow(100) - 1).unwrap(), "ia2bvpjaiju7g5uaxn5t");
21 assert_eq!(coder.encode_long(2_u128.pow(100)), Err(tesid::ValueTooLarge));
23 assert_eq!(coder.decode("w2ej"), Ok(0));
26 And with the most convenient form of type discrimination:
27 (You can also do all this through TesidCoder, but it’s less convenient.)
31 TesidCoder, TypedTesidCoder, DecodeError, SplitDecode,
32 define_type_discriminant,
34 define_type_discriminant!(sparsity=256,
36 #[derive(Debug, PartialEq, Eq)]
43 let secret_key = "000102030405060708090a0b0c0d0e0f";
44 let coder = TesidCoder::new(secret_key).unwrap();
45 let typed_coder = TypedTesidCoder::<Type>::new(coder);
47 assert_eq!(&*typed_coder.encode(Type::A, 0), "w2ej");
48 assert_eq!(&*typed_coder.encode(Type::B, 0), "w6um");
49 assert_eq!(&*typed_coder.encode(Type::C, 0), "x45g");
50 assert_eq!(&*typed_coder.encode(Type::A, 1), "dh2h");
51 assert_eq!(&*typed_coder.encode(Type::B, 1), "a6xy");
52 assert_eq!(&*typed_coder.encode(Type::C, 1), "7xgj");
53 assert_eq!(typed_coder.decode(Type::A, "w2ej"), Ok(0));
54 assert_eq!(typed_coder.decode(Type::B, "w2ej"),
55 Err(DecodeError::WrongDiscriminant { id: 0, discriminant: Type::A }));
56 assert_eq!(typed_coder.split_decode("w2ej"),
57 Ok(SplitDecode { id: 0, discriminant: Type::A }));
62 - **std**: currently only
`impl std::error::Error for tesid::{DecodeError, ValueTooLarge}`.
63 *Not* enabled by default.
67 **Authorship:**
[Chris Morgan](https://chrismorgan.info/) is the author and maintainer of this library.
69 **Licensing:** this library is distributed under the terms of the
70 [Blue Oak Model License 1.0.0](https://blueoakcouncil.org/license/1.0.0), the
71 [MIT License](https://opensource.org/licenses/MIT) and the
72 [Apache License, Version 2.0](https://www.apache.org/licenses/LICENSE-2.0), at your choice.
73 See [COPYRIGHT](COPYRIGHT) for details.