Skip to content

Commit 46a107c

Browse files
committed
fix: move unnecessary functions to test section
1 parent 3c6ee83 commit 46a107c

File tree

1 file changed

+34
-37
lines changed
  • modules/block_kes_validator/src/ouroboros

1 file changed

+34
-37
lines changed

modules/block_kes_validator/src/ouroboros/kes.rs

Lines changed: 34 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,7 @@
1-
use kes_summed_ed25519::{
2-
self as kes,
3-
kes::{Sum6Kes, Sum6KesSig},
4-
traits::{KesSig, KesSk},
5-
};
1+
use kes_summed_ed25519::{self as kes, kes::Sum6KesSig, traits::KesSig};
62
use std::{array::TryFromSliceError, ops::Deref};
73
use thiserror::Error;
84

9-
// ------------------------------------------------------------------- SecretKey
10-
11-
/// KES secret key
12-
pub struct SecretKey<'a>(Sum6Kes<'a>);
13-
14-
impl SecretKey<'_> {
15-
/// Create a new KES secret key
16-
pub fn from_bytes(sk_bytes: &mut Vec<u8>) -> Result<SecretKey<'_>, Error> {
17-
// TODO: extend() could potentially re-allocate memory to a new location and copy the sk_bytes.
18-
// This would leave the original memory containing the secret key without being wiped.
19-
sk_bytes.extend([0u8; 4]); // default to period = 0
20-
let sum_6_kes = Sum6Kes::from_bytes(sk_bytes.as_mut_slice())?;
21-
Ok(SecretKey(sum_6_kes))
22-
}
23-
24-
/// Get the current period of the KES secret key
25-
pub fn get_period(&self) -> u32 {
26-
self.0.get_period()
27-
}
28-
29-
/// Update the KES secret key to the next period
30-
pub fn update(&mut self) -> Result<(), Error> {
31-
Ok(self.0.update()?)
32-
}
33-
}
34-
355
// ------------------------------------------------------------------- PublicKey
366

377
/// KES public key
@@ -61,12 +31,6 @@ impl Deref for PublicKey {
6131
}
6232
}
6333

64-
impl From<&SecretKey<'_>> for PublicKey {
65-
fn from(sk: &SecretKey<'_>) -> Self {
66-
PublicKey(sk.0.to_pk())
67-
}
68-
}
69-
7034
impl From<&[u8; PublicKey::SIZE]> for PublicKey {
7135
fn from(bytes: &[u8; PublicKey::SIZE]) -> Self {
7236
PublicKey(kes::PublicKey::from_bytes(bytes).unwrap_or_else(|e| {
@@ -135,6 +99,39 @@ pub enum Error {
13599
#[cfg(test)]
136100
mod tests {
137101
use super::*;
102+
use kes_summed_ed25519::{kes::Sum6Kes, traits::KesSk};
103+
104+
// ------------------------------------------------------------------- SecretKey
105+
106+
/// KES secret key
107+
pub struct SecretKey<'a>(Sum6Kes<'a>);
108+
109+
impl SecretKey<'_> {
110+
/// Create a new KES secret key
111+
pub fn from_bytes(sk_bytes: &mut Vec<u8>) -> Result<SecretKey<'_>, Error> {
112+
// TODO: extend() could potentially re-allocate memory to a new location and copy the sk_bytes.
113+
// This would leave the original memory containing the secret key without being wiped.
114+
sk_bytes.extend([0u8; 4]); // default to period = 0
115+
let sum_6_kes = Sum6Kes::from_bytes(sk_bytes.as_mut_slice())?;
116+
Ok(SecretKey(sum_6_kes))
117+
}
118+
119+
/// Get the current period of the KES secret key
120+
pub fn get_period(&self) -> u32 {
121+
self.0.get_period()
122+
}
123+
124+
/// Update the KES secret key to the next period
125+
pub fn update(&mut self) -> Result<(), Error> {
126+
Ok(self.0.update()?)
127+
}
128+
}
129+
130+
impl From<&SecretKey<'_>> for PublicKey {
131+
fn from(sk: &SecretKey<'_>) -> Self {
132+
PublicKey(sk.0.to_pk())
133+
}
134+
}
138135

139136
#[test]
140137
fn kes_key_evolution() {

0 commit comments

Comments
 (0)