| Crates.io | squishyid |
| lib.rs | squishyid |
| version | 0.1.1 |
| created_at | 2024-05-01 23:40:13.55171+00 |
| updated_at | 2024-05-02 00:31:40.474005+00 |
| description | Shorten and obfuscate IDs. |
| homepage | |
| repository | https://github.com/bbkr/SquishyID |
| max_upload_size | |
| id | 1227321 |
| size | 10,531 |
Shorten and obfuscate IDs in Rust language.
Useful for:
use squishyid::SquishyID;
let s = SquishyID::new(
"2BjLhRduC6Tb8Q5cEk9oxnFaWUDpOlGAgwYzNre7tI4yqPvXm0KSV1fJs3ZiHM"
).unwrap();
let encoded: String = s.encode(48888851145);
assert_eq!(encoded, "1FN7Ab");
let decoded: u64 = s.decode("1FN7Ab").unwrap();
assert_eq!(decoded, 48888851145);
Constructs new instance using given key.
Choose your key characters wisely, for example:
a-z,A-Z,0-9 range. You will get excellent shortening like 1234567890 -> 380FQs.a-z range. You will get good shortening and avoid case insensitivity collisions, like 1234567890 -> iszbmfx.1234567890 will be represented as 😣😄😹😧😋😳.Errors:
Key must contain at least 2 characters.Key must contain unique characters.Encodes number using characters from the key.
Note that this should not be considered a strong encryption. It does not contain consistency checks. And key is easy to reverse engineer with small amount of encoded/decoded samples given. Treat it as really, really fast obfuscation only.
Decodes string using characters from the key.
Errors:
Encoded value must contain at least 1 character.
Encoded value contains character not present in key.
Encoded value too big to decode. - when it would cause u64 overflow.