From 45a323fd3b34dd5fb7704f80ddf0f8c144e56755 Mon Sep 17 00:00:00 2001 From: Jan Viktorin Date: Wed, 6 Mar 2024 11:18:19 +0100 Subject: [PATCH] ssh-key: introduce private::SkEd25519::new() constructor --- ssh-key/src/private/sk.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/ssh-key/src/private/sk.rs b/ssh-key/src/private/sk.rs index d5e0323..7fe395c 100644 --- a/ssh-key/src/private/sk.rs +++ b/ssh-key/src/private/sk.rs @@ -114,6 +114,24 @@ pub struct SkEd25519 { } impl SkEd25519 { + /// Construct new instance of SkEd25519. + #[cfg(feature = "alloc")] + pub fn new(public: public::SkEd25519, flags: u8, key_handle: impl Into>) -> Result { + let key_handle = key_handle.into(); + + if key_handle.len() <= 255 { + Ok(SkEd25519 { + public, + flags, + key_handle: key_handle.to_vec(), + reserved: Vec::::new(), + }) + } + else { + Err(Error::TooLong { bad_len: key_handle.len() }) + } + } + /// Get the Ed25519 public key. pub fn public(&self) -> &public::SkEd25519 { &self.public