changelog shortlog graph tags branches changeset files revisions annotate raw help

Mercurial > core / rust/lib/crypto/src/lib.rs

changeset 698: 96958d3eb5b0
parent: 4f49127c9048
author: Richard Westhaver <ellis@rwest.io>
date: Fri, 04 Oct 2024 22:04:59 -0400
permissions: -rw-r--r--
description: fixes
1 //! crypto modules
2 mod con;
3 
4 #[cfg(test)]
5 mod tests;
6 
7 use con::{PUBLIC_KEY_LENGTH, SECRET_KEY_LENGTH};
8 
9 pub use salsa20::{self, XSalsa20};
10 // use ed25519::signature::Signature as _;
11 use ed25519_dalek::*;
12 use hex::FromHex;
13 
14 pub fn gen_keypair<S: AsRef<[u8]>, P: AsRef<[u8]>>(
15  secret_key: S,
16  public_key: P,
17 ) -> Keypair {
18  let sec_bytes: Vec<u8> = FromHex::from_hex(secret_key).unwrap();
19  let pub_bytes: Vec<u8> = FromHex::from_hex(public_key).unwrap();
20  let secret: SecretKey =
21  SecretKey::from_bytes(&sec_bytes[..SECRET_KEY_LENGTH]).unwrap();
22  let public: PublicKey =
23  PublicKey::from_bytes(&pub_bytes[..PUBLIC_KEY_LENGTH]).unwrap();
24 
25  Keypair { secret, public }
26 }