Module aether_lib::identity
source · [−]Expand description
Primitives for representing PKC based user identities. Used to identify and authenticate users as well as for key exchange.
Current implementation uses RSA as the asymmetric encryption algorithm. But can be replaced in the future in favor of more efficient algorithms.
Identity Storage
The Id
is stored in $HOME/.config/aether/
by default. If $HOME
cannot be resolved, the
current working directory is used instead.
OpenSSL Errors
This library uses the OpenSSL wrapper for encryption
purposes. So, some of the functions can return AetherError::OpenSSLError
.
Check openssl::error::ErrorStack
for detailed description of OpenSSL errors.
Refer: https://www.openssl.org/
Examples
To load a new identity from the filesystem or create a new identity if not found use
load_or_generate()
use aether_lib::identity::Id;
let id = Id::load_or_generate().unwrap();
let plain_text = "A message to be encrypted";
// Returns a Vec<u8> of cipher text bytes
let cipher_text_bytes = id.public_encrypt(&plain_text.as_bytes()).unwrap();
// Returns a Vec<u8> of decrypted bytes
let decrypted_text_bytes = id.private_decrypt(&cipher_text_bytes).unwrap();
let plain_text_decrypted = String::from_utf8(decrypted_text_bytes).unwrap();
assert_eq!(plain_text, plain_text_decrypted);
To generate a new identity use new()
use aether_lib::identity::Id;
let id = Id::new().unwrap();
Structs
Primitive to represent and store the identity of a user. Used by a user to store their own identity. Uses asymmetric encryption as the basis for authentication.
Primitive to represent public identity of a user. Used by a user to store other users’
identities
Different from Id
as it is meant to be used to store only public key. So, only used to
represent identity of other users
Constants
Size of RSA keys to be used