use crate::{Error, Result, public};
use alloc::vec::Vec;
use encoding::{Decode, Encode};
#[cfg(all(feature = "alloc", feature = "ecdsa"))]
#[derive(Clone, Debug, Decode, Encode, Eq, PartialEq, PartialOrd, Ord)]
#[ssh(error = Error)]
pub struct SkEcdsaSha2NistP256 {
public: public::SkEcdsaSha2NistP256,
flags: u8,
key_handle: Vec<u8>,
reserved: Vec<u8>,
}
#[cfg(feature = "ecdsa")]
impl SkEcdsaSha2NistP256 {
#[cfg(feature = "alloc")]
pub fn new(
public: public::SkEcdsaSha2NistP256,
flags: u8,
key_handle: impl Into<Vec<u8>>,
) -> Result<Self> {
let key_handle = key_handle.into();
if key_handle.len() <= 255 {
Ok(SkEcdsaSha2NistP256 {
public,
flags,
key_handle,
reserved: Vec::<u8>::new(),
})
} else {
Err(encoding::Error::Length.into())
}
}
#[must_use]
pub fn public(&self) -> &public::SkEcdsaSha2NistP256 {
&self.public
}
#[must_use]
pub fn flags(&self) -> u8 {
self.flags
}
#[must_use]
pub fn key_handle(&self) -> &[u8] {
&self.key_handle
}
}
#[cfg(feature = "alloc")]
#[derive(Clone, Debug, Decode, Encode, Eq, PartialEq, PartialOrd, Ord)]
#[ssh(error = Error)]
pub struct SkEd25519 {
public: public::SkEd25519,
flags: u8,
key_handle: Vec<u8>,
reserved: Vec<u8>,
}
impl SkEd25519 {
#[cfg(feature = "alloc")]
pub fn new(
public: public::SkEd25519,
flags: u8,
key_handle: impl Into<Vec<u8>>,
) -> Result<Self> {
let key_handle = key_handle.into();
if key_handle.len() <= 255 {
Ok(SkEd25519 {
public,
flags,
key_handle,
reserved: Vec::<u8>::new(),
})
} else {
Err(encoding::Error::Length.into())
}
}
#[must_use]
pub fn public(&self) -> &public::SkEd25519 {
&self.public
}
#[must_use]
pub fn flags(&self) -> u8 {
self.flags
}
#[must_use]
pub fn key_handle(&self) -> &[u8] {
&self.key_handle
}
}