pub enum Key {
EC {
curve: Curve,
},
RSA {
public: RsaPublic,
private: Option<RsaPrivate>,
},
Symmetric {
key: ByteVec,
},
}
Variants§
EC
An elliptic curve, as per RFC 7518 §6.2.
RSA
An elliptic curve, as per RFC 7518 §6.3. See also: RFC 3447.
Symmetric
A symmetric key, as per RFC 7518 §6.4.
Implementations§
Source§impl Key
impl Key
Sourcepub fn is_private(&self) -> bool
pub fn is_private(&self) -> bool
Returns true iff this key only contains private components (i.e. a private asymmetric key or a symmetric key).
Sourcepub fn to_public(&self) -> Option<Cow<'_, Self>>
pub fn to_public(&self) -> Option<Cow<'_, Self>>
Returns the public part of this key (symmetric keys have no public parts).
Sourcepub fn try_to_der(&self) -> Result<Vec<u8>, ConversionError>
pub fn try_to_der(&self) -> Result<Vec<u8>, ConversionError>
If this key is asymmetric, encodes it as PKCS#8.
Sourcepub fn to_der(&self) -> Vec<u8> ⓘ
pub fn to_der(&self) -> Vec<u8> ⓘ
Unwrapping try_to_der
.
Panics if the key is not asymmetric or there are missing RSA components.
Sourcepub fn try_to_pem(&self) -> Result<String, ConversionError>
pub fn try_to_pem(&self) -> Result<String, ConversionError>
If this key is asymmetric, encodes it as PKCS#8 with PEM armoring.
Sourcepub fn to_pem(&self) -> String
pub fn to_pem(&self) -> String
Unwrapping try_to_pem
.
Panics if the key is not asymmetric or there are missing RSA components.
Sourcepub fn generate_symmetric(num_bits: usize) -> Self
pub fn generate_symmetric(num_bits: usize) -> Self
Generates a new symmetric key with the specified number of bits. Best used with one of the HS algorithms (e.g., HS256).
Sourcepub fn generate_p256() -> Self
pub fn generate_p256() -> Self
Generates a new EC keypair using the prime256 curve. Used with the ES256 algorithm.
Source§impl Key
impl Key
Sourcepub fn try_to_encoding_key(&self) -> Result<EncodingKey, ConversionError>
pub fn try_to_encoding_key(&self) -> Result<EncodingKey, ConversionError>
Returns an EncodingKey
if the key is private.
Sourcepub fn to_encoding_key(&self) -> EncodingKey
pub fn to_encoding_key(&self) -> EncodingKey
Unwrapping try_to_encoding_key
. Panics if the key is public.