Skip to content

Commit

Permalink
ok
Browse files Browse the repository at this point in the history
  • Loading branch information
cosmicexplorer committed Jun 27, 2022
1 parent 38548d3 commit 503d336
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions rust/protocol/src/curve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ use subtle::ConstantTimeEq;

/// Map the variant of key being used to and from a [u8].
///
/// Implements [SignalProtocolError::from] on top of [num_enum::TryFromPrimitive] to convert into
/// raising a [SignalProtocolError] if the encoded key variant is invalid.
///
///```
/// # fn main() -> libsignal_protocol::error::Result<()> {
/// use libsignal_protocol::KeyType;
Expand Down Expand Up @@ -80,7 +77,7 @@ impl From<TryFromPrimitiveError<KeyType>> for SignalProtocolError {
}
}

/// Interface for structs that perform operations parameterized by values of [KeyType].
/// Interface for structs that perform operations parameterized by values of [`KeyType`].
pub trait Keyed {
/// Return the variant of key this object employs.
fn key_type(&self) -> KeyType;
Expand All @@ -91,10 +88,10 @@ enum PublicKeyData {
Curve25519([u8; 32]),
}

/// Public key half of a [KeyPair].
/// Public key half of a [`KeyPair`].
///
/// Uses [Self::ct_eq] and [constant_time_cmp] to implement equality and ordering without leaking
/// too much information about the contents of the data being compared.
/// Uses [`Self::ct_eq`] and [`constant_time_cmp`] to implement equality and ordering without
/// leaking too much information about the contents of the data being compared.
#[derive(Clone, Copy)]
pub struct PublicKey {
key: PublicKeyData,
Expand Down Expand Up @@ -136,7 +133,8 @@ impl PublicKey {
}
}

/// Create an instance by attempting to interpret `bytes` as a [KeyType::Curve25519] public key.
/// Create an instance by attempting to interpret `bytes` as a [`KeyType::Curve25519`]
/// public key.
pub fn from_curve25519_public_key_bytes(bytes: &[u8]) -> Result<Self> {
match <[u8; curve25519::PUBLIC_KEY_LENGTH]>::try_from(bytes) {
Err(_) => Err(SignalProtocolError::BadKeyLength(
Expand All @@ -149,7 +147,7 @@ impl PublicKey {
}
}

/// Return a byte slice which can be deserialized with [Self::deserialize].
/// Return a byte slice which can be deserialized with [`Self::deserialize`].
pub fn serialize(&self) -> Box<[u8]> {
let value_len = match self.key {
PublicKeyData::Curve25519(v) => v.len(),
Expand Down Expand Up @@ -280,10 +278,11 @@ enum PrivateKeyData {
Curve25519([u8; curve25519::PRIVATE_KEY_LENGTH]),
}

/// Private key half of a [KeyPair].
/// Private key half of a [`KeyPair`].
///
/// Analogously to [PublicKey], uses [Self::ct_eq] and [constant_time_cmp] to implement equality and
/// ordering without leaking too much information about the contents of the data being compared.
/// Analogously to [`PublicKey`], uses [`Self::ct_eq`] and [`constant_time_cmp`] to implement
/// equality and ordering without leaking too much information about the contents of the data
/// being compared.
#[derive(Clone, Copy)]
pub struct PrivateKey {
key: PrivateKeyData,
Expand All @@ -310,7 +309,7 @@ impl PrivateKey {
}
}

/// Return a byte slice which can be deserialized with [Self::deserialize].
/// Return a byte slice which can be deserialized with [`Self::deserialize`].
pub fn serialize(&self) -> Vec<u8> {
match self.key {
PrivateKeyData::Curve25519(v) => v.to_vec(),
Expand Down Expand Up @@ -560,7 +559,7 @@ impl KeyPair {
))
}

/// Verify a signature for `message` produced by [Self::calculate_signature].
/// Verify a signature for `message` produced by [`Self::calculate_signature`].
///```
/// # fn main() -> Result<(), libsignal_protocol::error::SignalProtocolError> {
/// # use libsignal_protocol::KeyPair;
Expand Down

0 comments on commit 503d336

Please sign in to comment.