YubiKey plugin protocol

This commit is contained in:
Jack Grigg
2021-01-04 01:05:39 +00:00
parent 12df32817c
commit 5a85a15341
7 changed files with 598 additions and 12 deletions
+15
View File
@@ -33,6 +33,16 @@ impl fmt::Display for Recipient {
}
impl Recipient {
/// Attempts to parse a valid YubiKey recipient from its compressed SEC-1 byte encoding.
pub(crate) fn from_bytes(bytes: &[u8]) -> Option<Self> {
let encoded = p256::EncodedPoint::from_bytes(bytes).ok()?;
if encoded.is_compressed() {
Self::from_encoded(&encoded)
} else {
None
}
}
/// Attempts to parse a valid YubiKey recipient from its SEC-1 encoding.
///
/// This accepts both compressed (as used by the plugin) and uncompressed (as used in
@@ -50,4 +60,9 @@ impl Recipient {
let tag = Sha256::digest(self.to_string().as_bytes());
(&tag[0..TAG_BYTES]).try_into().expect("length is correct")
}
/// Exposes the wrapped public key.
pub(crate) fn public_key(&self) -> &p256::PublicKey {
&self.0
}
}