Add a generate keypair and auth secret helper method (#20)

This commit is contained in:
Edouard Oger 2019-03-12 16:24:58 -04:00 коммит произвёл JR Conlin
Родитель 6fb6700a3e
Коммит 7850661b08
2 изменённых файлов: 12 добавлений и 4 удалений

Просмотреть файл

@ -15,7 +15,7 @@ pub const ECE_SALT_LENGTH: usize = 16;
pub const ECE_TAG_LENGTH: usize = 16;
//const ECE_WEBPUSH_PRIVATE_KEY_LENGTH: usize = 32;
pub const ECE_WEBPUSH_PUBLIC_KEY_LENGTH: usize = 65;
const ECE_WEBPUSH_AUTH_SECRET_LENGTH: usize = 16;
pub const ECE_WEBPUSH_AUTH_SECRET_LENGTH: usize = 16;
const ECE_WEBPUSH_DEFAULT_RS: u32 = 4096;
// TODO: Make it nicer to use with a builder pattern.

Просмотреть файл

@ -12,14 +12,22 @@ mod error;
pub use crate::{
aes128gcm::Aes128GcmEceWebPush,
aesgcm::{AesGcmEceWebPush, AesGcmEncryptedBlock},
common::WebPushParams,
crypto_backend::{LocalKeyPair, RemotePublicKey},
common::{WebPushParams, ECE_WEBPUSH_AUTH_SECRET_LENGTH},
crypto_backend::{Crypto, LocalKeyPair, RemotePublicKey},
error::*,
};
pub type Aes128GcmEceWebPushImpl = aes128gcm::Aes128GcmEceWebPush<crypto_backends::CryptoImpl>;
pub type AesGcmEceWebPushImpl = aesgcm::AesGcmEceWebPush<crypto_backends::CryptoImpl>;
pub use crate::crypto_backends::{LocalKeyPairImpl, RemoteKeyPairImpl};
pub use crate::crypto_backends::{CryptoImpl, LocalKeyPairImpl, RemoteKeyPairImpl};
pub fn generate_keypair_and_auth_secret(
) -> Result<(LocalKeyPairImpl, [u8; ECE_WEBPUSH_AUTH_SECRET_LENGTH])> {
let local_key_pair = LocalKeyPairImpl::generate_random()?;
let mut auth_secret = [0u8; ECE_WEBPUSH_AUTH_SECRET_LENGTH];
CryptoImpl::random(&mut auth_secret)?;
Ok((local_key_pair, auth_secret))
}
#[cfg(test)]
mod aes128gcm_tests {