mirror of
https://github.com/MercuryWorkshop/epoxy-tls.git
synced 2025-05-13 06:20:02 -04:00
add to simple wisp client
This commit is contained in:
parent
577ce71b89
commit
24ccd8d393
7 changed files with 82 additions and 9 deletions
|
@ -74,7 +74,10 @@ pub struct VerifyKey {
|
|||
|
||||
impl VerifyKey {
|
||||
/// Create a new ED25519 verification key.
|
||||
pub fn new_ed25519(verifier: Arc<dyn Verifier<Signature> + Sync + Send>, hash: [u8; 64]) -> Self {
|
||||
pub fn new_ed25519(
|
||||
verifier: Arc<dyn Verifier<Signature> + Sync + Send>,
|
||||
hash: [u8; 64],
|
||||
) -> Self {
|
||||
Self {
|
||||
cert_type: SupportedCertificateTypes::Ed25519,
|
||||
hash,
|
||||
|
@ -314,9 +317,9 @@ impl ProtocolExtensionBuilder for CertAuthProtocolExtensionBuilder {
|
|||
fn build_to_extension(&mut self, _: Role) -> Result<AnyProtocolExtension, WispError> {
|
||||
match self {
|
||||
Self::ServerBeforeChallenge { verifiers } => {
|
||||
let mut challenge = BytesMut::with_capacity(64);
|
||||
let mut challenge = [0u8; 64];
|
||||
getrandom::getrandom(&mut challenge).map_err(CertAuthError::from)?;
|
||||
let challenge = challenge.freeze();
|
||||
let challenge = Bytes::from(challenge.to_vec());
|
||||
|
||||
*self = Self::ServerAfterChallenge {
|
||||
verifiers: verifiers.to_vec(),
|
||||
|
|
|
@ -32,6 +32,16 @@ impl AnyProtocolExtension {
|
|||
pub fn downcast<T: ProtocolExtension>(self) -> Result<Box<T>, Self> {
|
||||
self.0.__downcast().map_err(Self)
|
||||
}
|
||||
|
||||
/// Downcast the protocol extension.
|
||||
pub fn downcast_ref<T: ProtocolExtension>(&self) -> Option<&T> {
|
||||
self.0.__downcast_ref()
|
||||
}
|
||||
|
||||
/// Downcast the protocol extension.
|
||||
pub fn downcast_mut<T: ProtocolExtension>(&mut self) -> Option<&mut T> {
|
||||
self.0.__downcast_mut()
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref for AnyProtocolExtension {
|
||||
|
@ -126,6 +136,22 @@ impl dyn ProtocolExtension {
|
|||
Err(self)
|
||||
}
|
||||
}
|
||||
|
||||
fn __downcast_ref<T: ProtocolExtension>(&self) -> Option<&T> {
|
||||
if self.__is::<T>() {
|
||||
unsafe { Some(&*(self as *const dyn ProtocolExtension as *const T)) }
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
fn __downcast_mut<T: ProtocolExtension>(&mut self) -> Option<&mut T> {
|
||||
if self.__is::<T>() {
|
||||
unsafe { Some(&mut *(self as *mut dyn ProtocolExtension as *mut T)) }
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Trait to build a Wisp protocol extension from a payload.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue