### Example OID Source: https://docs.rs/ed25519-dalek/2.2.0/ed25519_dalek/pkcs8/spki/der/oid/index.html An example of an OID identifying the rsaEncryption algorithm. ```plaintext 1.2.840.113549.1.1.1 ``` -------------------------------- ### Batch Signature Verification Example Source: https://docs.rs/ed25519-dalek/2.2.0/ed25519_dalek/fn.verify_batch.html Demonstrates how to generate multiple key pairs, sign messages, and then verify all signatures in a batch using the verify_batch function. This snippet requires the 'batch' feature to be enabled. ```rust use ed25519_dalek::{ verify_batch, SigningKey, VerifyingKey, Signer, Signature, }; use rand::rngs::OsRng; let mut csprng = OsRng; let signing_keys: Vec<_> = (0..64).map(|_| SigningKey::generate(&mut csprng)).collect(); let msg: &[u8] = b"They're good dogs Brant"; let messages: Vec<_> = (0..64).map(|_| msg).collect(); let signatures: Vec<_> = signing_keys.iter().map(|key| key.sign(&msg)).collect(); let verifying_keys: Vec<_> = signing_keys.iter().map(|key| key.verifying_key()).collect(); let result = verify_batch(&messages, &signatures, &verifying_keys); assert!(result.is_ok()); ``` -------------------------------- ### Example of Using Ed25519 Context for Signing and Verification Source: https://docs.rs/ed25519-dalek/2.2.0/ed25519_dalek/struct.Context.html Demonstrates how to create and use Ed25519 contexts for signing and verifying prehashed messages. Requires the 'digest' feature. ```rust use ed25519_dalek::{Signature, SigningKey, VerifyingKey, Sha512}; use ed25519_dalek::{DigestSigner, DigestVerifier}; let context_str = b"Local Channel 3"; let prehashed_message = Sha512::default().chain_update(b"Stay tuned for more news at 7"); // Signer let signing_context = signing_key.with_context(context_str).unwrap(); let signature = signing_context.sign_digest(prehashed_message.clone()); // Verifier let verifying_context = verifying_key.with_context(context_str).unwrap(); let verified: bool = verifying_context .verify_digest(prehashed_message, &signature) .is_ok(); ``` -------------------------------- ### PEM Encoding and Decoding Source: https://docs.rs/ed25519-dalek/2.2.0/ed25519_dalek/pkcs8/spki/der/pem/index.html Demonstrates how to decode a PEM-encoded string into its type label and data, and how to encode data back into a PEM-encoded string. This example uses a sample private key PEM document. ```APIDOC ## PEM Encoding and Decoding ### Description This example demonstrates the basic usage of the `pem_rfc7468` crate for decoding and encoding PEM documents. It shows how to parse a PEM string to extract the type label and the raw data, and then how to re-encode that data back into a PEM string. ### Usage ```rust // Decode PEM let example_pem = "-----BEGIN PRIVATE KEY-----\nMC4CAQAwBQYDK2VwBCIEIBftnHPp22SewYmmEoMcX8VwI4IHwaqd+9LFPj/15eqF\n-----END PRIVATE KEY-----"; let (type_label, data) = pem_rfc7468::decode_vec(example_pem.as_bytes()).expect("Failed to decode PEM"); assert_eq!(type_label, "PRIVATE KEY"); assert_eq!( data, &[ 48, 46, 2, 1, 0, 48, 5, 6, 3, 43, 101, 112, 4, 34, 4, 32, 23, 237, 156, 115, 233, 219, 100, 158, 193, 137, 166, 18, 131, 28, 95, 197, 112, 35, 130, 7, 193, 170, 157, 251, 210, 197, 62, 63, 245, 229, 234, 133 ] ); // Encode PEM use pem_rfc7468::LineEnding; let encoded_pem = pem_rfc7468::encode_string(type_label, LineEnding::default(), &data).expect("Failed to encode PEM"); assert_eq!(&encoded_pem, example_pem); ``` ### Functions Used - `pem_rfc7468::decode_vec`: Decodes a PEM document into a type label and data. - `pem_rfc7468::encode_string`: Encodes a type label and data into a PEM document string. ### Notes - The `example_pem` string includes newline characters (`\n`) for proper formatting. - Error handling is done using `.expect()` for brevity in the example; in production code, proper error handling with `Result` should be used. ``` -------------------------------- ### Rust: Create and Encode AlgorithmIdentifier Source: https://docs.rs/ed25519-dalek/2.2.0/ed25519_dalek/pkcs8/spki/der/index.html Demonstrates creating an `AlgorithmIdentifier` instance with specific OIDs for algorithm and parameters, then encoding it into DER format. This example requires the `alloc` feature for serialization to a `Vec`. ```rust // Example parameters value: OID for the NIST P-256 elliptic curve. let parameters = "1.2.840.10045.3.1.7".parse::().unwrap(); // We need to convert `parameters` into an `Any<'a>` type, which wraps a // `&'a [u8]` byte slice. // // To do that, we need owned DER-encoded data so that we can have // `AnyRef` borrow a reference to it, so we have to serialize the OID. // // When the `alloc` feature of this crate is enabled, any type that impls // the `Encode` trait including all ASN.1 built-in types and any type // which impls `Sequence` can be serialized by calling `Encode::to_der()`. let der_encoded_parameters = parameters.to_der().unwrap(); let algorithm_identifier = AlgorithmIdentifier { // OID for `id-ecPublicKey`, if you're curious algorithm: "1.2.840.10045.2.1".parse().unwrap(), // `Any<'a>` impls `TryFrom<&'a [u8]>`, which parses the provided // slice as an ASN.1 DER-encoded message. parameters: Some(der_encoded_parameters.as_slice().try_into().unwrap()) }; // Serialize the `AlgorithmIdentifier` created above as ASN.1 DER, // allocating a `Vec` for storage. // // As mentioned earlier, if you don't have the `alloc` feature enabled you ``` -------------------------------- ### new Source: https://docs.rs/ed25519-dalek/2.2.0/ed25519_dalek/type.Sha512.html Creates a new `CoreWrapper` instance using a fixed-size key. This is the primary method for initializing the hasher with a specific key. ```APIDOC ## fn new( key: &GenericArray as KeySizeUser>::KeySize>, ) -> CoreWrapper ### Description Create new value from fixed size key. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) - **CoreWrapper**: A new instance of CoreWrapper. ### Response Example None ERROR HANDLING: None ``` -------------------------------- ### Context Implementations Source: https://docs.rs/ed25519-dalek/2.2.0/ed25519_dalek/struct.Context.html Provides details on the methods and constants associated with the `Context` struct, including its maximum length and methods for borrowing the key and value. ```APIDOC ### impl<'k, 'v, K> Context<'k, 'v, K> #### pub const MAX_LENGTH: usize = 255usize Maximum length of the context value in octets. #### pub fn key(&self) -> &'k K Borrow the key. #### pub fn value(&self) -> &'v [u8] Borrow the context string value. ``` -------------------------------- ### Getting Mutable References with as_mut() Source: https://docs.rs/ed25519-dalek/2.2.0/ed25519_dalek/pkcs8/spki/der/oid/type.Result.html Shows how to use `as_mut()` to get mutable references to the contained values of a `Result`. This allows in-place modification of the success or error value. ```Rust fn mutate(r: &mut Result) { match r.as_mut() { Ok(v) => *v = 42, Err(e) => *e = 0, } } let mut x: Result = Ok(2); mutate(&mut x); assert_eq!(x.unwrap(), 42); let mut x: Result = Err(13); mutate(&mut x); assert_eq!(x.unwrap_err(), 0); ``` -------------------------------- ### type_id Source: https://docs.rs/ed25519-dalek/2.2.0/ed25519_dalek/pkcs8/spki/der/oid/struct.Arcs.html Gets the TypeId of self. ```APIDOC ## fn type_id(&self) -> TypeId ### Description Gets the `TypeId` of `self`. ### Returns The `TypeId` of the object. ``` -------------------------------- ### Generate SigningKey and Prepare for Signing Source: https://docs.rs/ed25519-dalek/2.2.0/ed25519_dalek/struct.SigningKey.html Demonstrates generating a new Ed25519 signing key and preparing a message for prehashed signing. Requires the 'digest' feature. ```rust use ed25519_dalek::Digest; use ed25519_dalek::SigningKey; use ed25519_dalek::Signature; use sha2::Sha512; use rand::rngs::OsRng; let mut csprng = OsRng; let signing_key: SigningKey = SigningKey::generate(&mut csprng); let message: &[u8] = b"All I want is to pet all of the dogs."; // Create a hash digest object which we'll feed the message into: let mut prehashed: Sha512 = Sha512::new(); prehashed.update(message); ``` -------------------------------- ### SigningKey::verifying_key Source: https://docs.rs/ed25519-dalek/2.2.0/ed25519_dalek/struct.SigningKey.html Gets the `VerifyingKey` for this `SigningKey`. ```APIDOC ## `SigningKey::verifying_key` ### Description Get the `VerifyingKey` for this `SigningKey`. ### Method `verifying_key` ### Returns A `VerifyingKey` instance. ``` -------------------------------- ### Derive Zeroize and ZeroizeOnDrop for a Struct Source: https://docs.rs/ed25519-dalek/2.2.0/ed25519_dalek/pkcs8/spki/der/zeroize/index.html This example shows how to derive both the Zeroize and ZeroizeOnDrop traits for a struct, ensuring its contents are zeroed out when the struct is dropped. ```rust use zeroize::{Zeroize, ZeroizeOnDrop}; // This struct will be zeroized on drop #[derive(Zeroize, ZeroizeOnDrop)] struct MyStruct([u8; 32]); ``` -------------------------------- ### UintRef::len Source: https://docs.rs/ed25519-dalek/2.2.0/ed25519_dalek/pkcs8/spki/der/asn1/struct.UintRef.html Get the length of this `UintRef` in bytes. ```APIDOC ### pub fn len(&self) -> Length Get the length of this `UintRef` in bytes. ``` -------------------------------- ### Create New PrivateKeyInfo Source: https://docs.rs/ed25519-dalek/2.2.0/ed25519_dalek/pkcs8/struct.PrivateKeyInfo.html Helper method to create a new PKCS#8 PrivateKeyInfo, initializing attributes and public_key to None. ```rust pub fn new( algorithm: AlgorithmIdentifier>, private_key: &'a [u8], ) -> PrivateKeyInfo<'a> ``` -------------------------------- ### try_from<&KeypairBytes> Source: https://docs.rs/ed25519-dalek/2.2.0/ed25519_dalek/struct.SigningKey.html Attempts to create a SigningKey from `KeypairBytes`. This is useful for importing key material. Available when the `pkcs8` crate feature is enabled. ```APIDOC ## try_from<&KeypairBytes> ### Description Performs the conversion. Available on `crate feature 'pkcs8'` only. ### Method `try_from(keypair_bytes: &KeypairBytes) -> Result` ### Error Type `type Error = Error;` ``` -------------------------------- ### ObjectIdentifier::len Source: https://docs.rs/ed25519-dalek/2.2.0/ed25519_dalek/pkcs8/spki/der/asn1/struct.ObjectIdentifier.html Gets the length of this `ObjectIdentifier` in arcs. ```APIDOC ### pub fn len(&self) -> usize Get the length of this `ObjectIdentifier` in arcs. ``` -------------------------------- ### ObjectIdentifier::parent Source: https://docs.rs/ed25519-dalek/2.2.0/ed25519_dalek/pkcs8/spki/der/asn1/struct.ObjectIdentifier.html Gets the parent OID of this one, if applicable. ```APIDOC ### pub fn parent(&self) -> Option Get the parent OID of this one (if applicable). ``` -------------------------------- ### Create PemReader Instance Source: https://docs.rs/ed25519-dalek/2.2.0/ed25519_dalek/pkcs8/spki/der/struct.PemReader.html Initializes a new PemReader for on-the-fly PEM decoding. It uses a default line wrapping of 64 characters. Requires the 'pkcs8' feature. ```rust pub fn new(pem: &'i [u8]) -> Result, Error> ``` -------------------------------- ### GeneralizedTime Conversions Source: https://docs.rs/ed25519-dalek/2.2.0/ed25519_dalek/pkcs8/spki/der/asn1/struct.GeneralizedTime.html Demonstrates how to convert GeneralizedTime from different types like SystemTime and AnyRef. ```APIDOC ## GeneralizedTime Conversions ### `impl<'__der> TryFrom<&'__der Any> for GeneralizedTime` #### `type Error = Error` The type returned in the event of a conversion error. #### `fn try_from(any: &'__der Any) -> Result` Performs the conversion from `&'__der Any` to `GeneralizedTime`. ### `impl TryFrom<&SystemTime> for GeneralizedTime` #### `type Error = Error` The type returned in the event of a conversion error. #### `fn try_from(time: &SystemTime) -> Result` Performs the conversion from `&SystemTime` to `GeneralizedTime`. ### `impl<'__der> TryFrom> for GeneralizedTime` #### `type Error = Error` The type returned in the event of a conversion error. #### `fn try_from(any: AnyRef<'__der>) -> Result` Performs the conversion from `AnyRef<'__der>` to `GeneralizedTime`. ### `impl TryFrom for GeneralizedTime` #### `type Error = Error` The type returned in the event of a conversion error. #### `fn try_from(time: SystemTime) -> Result` Performs the conversion from `SystemTime` to `GeneralizedTime`. ``` -------------------------------- ### Get TagNumber Value Source: https://docs.rs/ed25519-dalek/2.2.0/ed25519_dalek/pkcs8/spki/der/struct.TagNumber.html Retrieves the inner u8 value of the TagNumber. ```rust pub fn value(self) -> u8 ``` -------------------------------- ### Get Unused Bits Source: https://docs.rs/ed25519-dalek/2.2.0/ed25519_dalek/pkcs8/spki/der/asn1/struct.BitStringRef.html Retrieves the number of unused bits in the BitStringRef. ```rust pub fn unused_bits(&self) -> u8 ``` -------------------------------- ### impl TryFrom> for KeypairBytes Source: https://docs.rs/ed25519-dalek/2.2.0/ed25519_dalek/pkcs8/struct.KeypairBytes.html Attempts to convert a PrivateKeyInfo into a KeypairBytes instance. ```APIDOC ## impl TryFrom> for KeypairBytes ### type Error = Error ### fn try_from(private_key: PrivateKeyInfo<'_>) -> Result **Description:** Performs the conversion. **Parameters:** * `private_key`: A `PrivateKeyInfo` instance. **Returns:** A `Result` containing a `KeypairBytes` instance on success, or an `Error` on failure. ``` -------------------------------- ### Verify a Prehashed Signature with Context Source: https://docs.rs/ed25519-dalek/2.2.0/ed25519_dalek/struct.SigningKey.html Demonstrates verifying a signature on a prehashed message with an optional context. This example requires creating a new digest object as Sha512 does not implement Copy. Requires the 'digest' feature. ```rust use ed25519_dalek::Digest; use ed25519_dalek::SigningKey; use ed25519_dalek::Signature; use ed25519_dalek::SignatureError; use sha2::Sha512; use rand::rngs::OsRng; let mut csprng = OsRng; let signing_key: SigningKey = SigningKey::generate(&mut csprng); let message: &[u8] = b"All I want is to pet all of the dogs."; let mut prehashed: Sha512 = Sha512::new(); prehashed.update(message); let context: &[u8] = b"Ed25519DalekSignPrehashedDoctest"; let sig: Signature = signing_key.sign_prehashed(prehashed, Some(context))?; // The sha2::Sha512 struct doesn't implement Copy, so we'll have to create a new one: let mut prehashed_again: Sha512 = Sha512::default(); prehashed_again.update(message); let verified = signing_key.verifying_key().verify_prehashed(prehashed_again, Some(context), &sig); assert!(verified.is_ok()); ``` -------------------------------- ### Get the parent ObjectIdentifier Source: https://docs.rs/ed25519-dalek/2.2.0/ed25519_dalek/pkcs8/spki/der/asn1/struct.ObjectIdentifier.html Retrieve the parent OID of the current ObjectIdentifier, if it exists. ```rust pub fn parent(&self) -> Option ``` -------------------------------- ### TryFrom, BitStringRef<'_>>> for VerifyingKey Source: https://docs.rs/ed25519-dalek/2.2.0/ed25519_dalek/struct.VerifyingKey.html Converts a SubjectPublicKeyInfo reference into a VerifyingKey. This is available only when the 'pkcs8' crate feature is enabled. ```APIDOC ## impl TryFrom, BitStringRef<'_>>> for VerifyingKey Available on **crate feature`pkcs8`** only. ### type Error = Error The type returned in the event of a conversion error. ### fn try_from(public_key: SubjectPublicKeyInfoRef<'_>) -> Result Performs the conversion. ``` -------------------------------- ### Get s Component Bytes Source: https://docs.rs/ed25519-dalek/2.2.0/ed25519_dalek/struct.Signature.html Retrieves the 32-byte array representing the 's' component of the signature. ```rust pub fn s_bytes(&self) -> &[u8; 32] ``` -------------------------------- ### Tagged for T Source: https://docs.rs/ed25519-dalek/2.2.0/ed25519_dalek/pkcs8/spki/struct.ObjectIdentifier.html Provides a method to get the ASN.1 tag associated with a type that implements `FixedTag`. ```APIDOC ### impl Tagged for T where T: FixedTag, #### fn tag(&self) -> Tag ### Description Get the ASN.1 tag that this type is encoded with. ### Returns - `Tag` - The ASN.1 tag of the type. ``` -------------------------------- ### Initialize Decoder with Default Options Source: https://docs.rs/ed25519-dalek/2.2.0/ed25519_dalek/pkcs8/spki/der/pem/struct.Decoder.html Creates a new Decoder instance with default settings, including 64-character line wrapping. Use this for standard PEM decoding. ```rust pub fn new(pem: &'i [u8]) -> Result, Error> ``` -------------------------------- ### Get Input Length Source: https://docs.rs/ed25519-dalek/2.2.0/ed25519_dalek/pkcs8/spki/der/struct.PemReader.html Returns the total length of the input data being processed by the PemReader. ```rust fn input_len(&self) -> Length ``` -------------------------------- ### Get Tag Class Source: https://docs.rs/ed25519-dalek/2.2.0/ed25519_dalek/pkcs8/spki/der/enum.Tag.html The `class` method retrieves the `Class` associated with a given `Tag`. ```rust pub fn class(self) -> Class ``` -------------------------------- ### Conversions to AnyRef Source: https://docs.rs/ed25519-dalek/2.2.0/ed25519_dalek/pkcs8/spki/der/asn1/struct.AnyRef.html Demonstrates how to convert different string reference types into AnyRef. ```APIDOC ## Conversions to AnyRef This section details the methods available for converting various string reference types into `AnyRef`. ### From TeletexStringRef ```rust fn from(teletex_string: TeletexStringRef<'a>) -> AnyRef<'a> ``` Converts to this type from the input type. ### From Utf8StringRef ```rust fn from(utf_string: Utf8StringRef<'a>) -> AnyRef<'a> ``` Converts to this type from the input type. ### From VideotexStringRef ```rust fn from(printable_string: VideotexStringRef<'a>) -> AnyRef<'a> ``` Converts to this type from the input type. ``` -------------------------------- ### Get SetOfVec as a slice Source: https://docs.rs/ed25519-dalek/2.2.0/ed25519_dalek/pkcs8/spki/der/asn1/struct.SetOfVec.html Borrows the elements of the SetOfVec as a slice, providing read-only access. ```rust pub fn as_slice(&self) -> &[T] ``` -------------------------------- ### Ia5String Conversions Source: https://docs.rs/ed25519-dalek/2.2.0/ed25519_dalek/pkcs8/spki/der/asn1/struct.Ia5String.html Demonstrates how to convert various types into Ia5String using the `try_from` method. ```APIDOC ## Ia5String Conversions This section details the methods available for converting other types into `Ia5String`. ### `impl<'__der> TryFrom<&'__der Any> for Ia5String` #### fn try_from(any: &'__der Any) -> Result Performs the conversion from an `Any` type to `Ia5String`. ### `impl<'__der> TryFrom> for Ia5String` #### fn try_from(any: AnyRef<'__der>) -> Result Performs the conversion from an `AnyRef` type to `Ia5String`. ### `impl TryFrom for Ia5String` #### fn try_from(input: String) -> Result Performs the conversion from a `String` to `Ia5String`. ``` -------------------------------- ### type_id(&self) -> TypeId Source: https://docs.rs/ed25519-dalek/2.2.0/ed25519_dalek/pkcs8/spki/der/asn1/struct.PrintableString.html Gets the `TypeId` of the current type. This is part of the `Any` trait implementation. ```APIDOC ## fn type_id(&self) -> TypeId ### Description Gets the `TypeId` of `self`. ### Method type_id ### Parameters - **self** (*&Self*) - The instance to get the type ID from. ### Response - **Success Response**: `TypeId` - The unique identifier for the type of `self`. ``` -------------------------------- ### fmt Source: https://docs.rs/ed25519-dalek/2.2.0/ed25519_dalek/struct.VerifyingKey.html Formats the VerifyingKey using the given formatter. ```APIDOC ## fmt ### Description Formats the value using the given formatter. ### Method `fn` ### Parameters #### Path Parameters - **f** (`&mut Formatter<'_>`) - Required - The formatter to use. ### Returns `Result<(), Result>` - A result indicating success or failure during formatting. ``` -------------------------------- ### Get the number of arcs in ObjectIdentifier Source: https://docs.rs/ed25519-dalek/2.2.0/ed25519_dalek/pkcs8/spki/der/asn1/struct.ObjectIdentifier.html Return the total number of arcs (nodes) in the ObjectIdentifier. ```rust pub fn len(&self) -> usize ``` -------------------------------- ### Get Bit Length Source: https://docs.rs/ed25519-dalek/2.2.0/ed25519_dalek/pkcs8/spki/der/asn1/struct.BitStringRef.html Calculates and returns the total length of the BIT STRING in bits. ```rust pub fn bit_len(&self) -> usize ``` -------------------------------- ### impl TryFrom for SigningKey Source: https://docs.rs/ed25519-dalek/2.2.0/ed25519_dalek/pkcs8/struct.KeypairBytes.html Attempts to convert KeypairBytes into a SigningKey. ```APIDOC ## impl TryFrom for SigningKey ### type Error = Error ### fn try_from(pkcs8_key: KeypairBytes) -> Result **Description:** Performs the conversion. **Parameters:** * `pkcs8_key`: A `KeypairBytes` instance. **Returns:** A `Result` containing a `SigningKey` on success, or an `Error` on failure. ``` -------------------------------- ### Create New PEM Encoder (Default Options) Source: https://docs.rs/ed25519-dalek/2.2.0/ed25519_dalek/pkcs8/spki/der/pem/struct.Encoder.html Initializes a new PEM Encoder with default settings, writing to a provided buffer. Uses 64-character line wrapping. ```rust pub fn new( type_label: &'l str, line_ending: LineEnding, out: &'o mut [u8], ) -> Result, Error> ``` -------------------------------- ### Get R Component Bytes Source: https://docs.rs/ed25519-dalek/2.2.0/ed25519_dalek/struct.Signature.html Retrieves the 32-byte array representing the 'R' component of the signature. ```rust pub fn r_bytes(&self) -> &[u8; 32] ``` -------------------------------- ### TryFrom for VerifyingKey Source: https://docs.rs/ed25519-dalek/2.2.0/ed25519_dalek/struct.VerifyingKey.html Converts an owned PublicKeyBytes into a VerifyingKey. This is available only when the 'pkcs8' crate feature is enabled. ```APIDOC ## impl TryFrom for VerifyingKey Available on **crate feature`pkcs8`** only. ### type Error = Error The type returned in the event of a conversion error. ### fn try_from(pkcs8_key: PublicKeyBytes) -> Result Performs the conversion. ``` -------------------------------- ### Get ASN.1 tag for BitStringRef Source: https://docs.rs/ed25519-dalek/2.2.0/ed25519_dalek/pkcs8/struct.BitStringRef.html Retrieves the ASN.1 tag associated with the BitStringRef, which is Tag::BitString. ```rust const TAG: Tag = Tag::BitString ``` -------------------------------- ### from (VerifyingKey to EdwardsPoint) Source: https://docs.rs/ed25519-dalek/2.2.0/ed25519_dalek/struct.VerifyingKey.html Converts a VerifyingKey into an EdwardsPoint. ```APIDOC ## from (VerifyingKey to EdwardsPoint) ### Description Converts to this type from the input type. ### Method `fn` ### Parameters #### Path Parameters - **vk** (`VerifyingKey`) - Required - The VerifyingKey to convert. ### Returns `EdwardsPoint` - The EdwardsPoint representation of the VerifyingKey. ``` -------------------------------- ### Get Remaining Length Source: https://docs.rs/ed25519-dalek/2.2.0/ed25519_dalek/pkcs8/spki/der/struct.PemReader.html Returns the number of bytes that are still available to be read from the input stream. ```rust fn remaining_len(&self) -> Length ``` -------------------------------- ### from (SigningKey) Source: https://docs.rs/ed25519-dalek/2.2.0/ed25519_dalek/struct.VerifyingKey.html Converts a SigningKey into a VerifyingKey. ```APIDOC ## from (SigningKey) ### Description Converts to this type from the input type. ### Method `fn` ### Parameters #### Path Parameters - **signing_key** (`&SigningKey`) - Required - The signing key to convert from. ### Returns `VerifyingKey` - The VerifyingKey derived from the signing key. ``` -------------------------------- ### Get Current Position Source: https://docs.rs/ed25519-dalek/2.2.0/ed25519_dalek/pkcs8/spki/der/struct.PemReader.html Returns the current reading position (offset) within the input data. ```rust fn position(&self) -> Length ``` -------------------------------- ### SigningKey::try_from (PrivateKeyInfo) Source: https://docs.rs/ed25519-dalek/2.2.0/ed25519_dalek/struct.SigningKey.html Attempts to create a SigningKey from a PrivateKeyInfo struct. This conversion is available when the 'pkcs8' feature is enabled. ```APIDOC ## SigningKey::try_from (PrivateKeyInfo) ### Description Performs the conversion from `PrivateKeyInfo` to `SigningKey`. ### Method ``` fn try_from(private_key: PrivateKeyInfo<'_>) -> Result ``` ### Type Alias ``` type Error = Error ``` ### Availability Available on **crate feature`pkcs8`** only. ``` -------------------------------- ### Trait RefToOwned Source: https://docs.rs/ed25519-dalek/2.2.0/ed25519_dalek/pkcs8/spki/der/referenced/trait.RefToOwned.html A trait for cloning a referenced structure and getting owned objects. This is the pendant to `OwnedToRef`. ```APIDOC ## Trait RefToOwned<'a> ### Description A trait for cloning a referenced structure and getting owned objects. This is the pendant to `OwnedToRef`. ### Associated Types #### type Owned: OwnedToRef = Self> where Self: 'a The resulting type after obtaining ownership. ### Methods #### fn ref_to_owned(&self) -> Self::Owned Creates a new object taking ownership of the data. ``` -------------------------------- ### Converting Result to Option with ok() Source: https://docs.rs/ed25519-dalek/2.2.0/ed25519_dalek/pkcs8/spki/der/oid/type.Result.html Shows how to use the `ok()` method to convert a `Result` into an `Option`, discarding any error value. This is useful when only the success value is of interest. ```Rust let x: Result = Ok(2); assert_eq!(x.ok(), Some(2)); let x: Result = Err("Nothing here"); assert_eq!(x.ok(), None); ``` -------------------------------- ### Get PEM Type Label Source: https://docs.rs/ed25519-dalek/2.2.0/ed25519_dalek/pkcs8/spki/der/pem/struct.Encoder.html Retrieves the PEM type label configured for this encoder instance. ```rust pub fn type_label(&self) -> &'l str ``` -------------------------------- ### AnyRef Implementations Source: https://docs.rs/ed25519-dalek/2.2.0/ed25519_dalek/pkcs8/spki/der/asn1/struct.AnyRef.html Provides methods for creating, decoding, and inspecting AnyRef values, along with implementations for various traits. ```APIDOC ### impl<'a> AnyRef<'a> #### pub const NULL: AnyRef<'a> `AnyRef` representation of the ASN.1 `NULL` type. #### pub fn new(tag: Tag, bytes: &'a [u8]) -> Result, Error> Create a new `AnyRef` from the provided `Tag` and DER bytes. #### pub fn value(self) -> &'a [u8] Get the raw value for this `AnyRef` type as a byte slice. #### pub fn decode_as(self) -> Result where T: Choice<'a> + DecodeValue<'a>, Attempt to decode this `AnyRef` type into the inner value. #### pub fn is_null(self) -> bool Is this value an ASN.1 `NULL` value? #### pub fn sequence(self, f: F) -> Result where F: FnOnce(&mut SliceReader<'a>) -> Result, Attempt to decode this value an ASN.1 `SEQUENCE`, creating a new nested reader and calling the provided argument with it. ### impl<'a> Choice<'a> for AnyRef<'a> #### fn can_decode(_: Tag) -> bool Is the provided `Tag` decodable as a variant of this `CHOICE`? ### impl<'a> Clone for AnyRef<'a> #### fn clone(&self) -> AnyRef<'a> Returns a duplicate of the value. Read more 1.0.0 · Source #### fn clone_from(&mut self, source: &Self) Performs copy-assignment from `source`. Read more ### impl<'a> Debug for AnyRef<'a> #### fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> Formats the value using the given formatter. Read more ### impl<'a> Decode<'a> for AnyRef<'a> #### fn decode(reader: &mut R) -> Result, Error> where R: Reader<'a>, Attempt to decode this message using the provided decoder. #### fn from_der(bytes: &'a [u8]) -> Result Parse `Self` from the provided DER-encoded byte slice. ### impl<'a> DecodeValue<'a> for AnyRef<'a> #### fn decode_value(reader: &mut R, header: Header) -> Result, Error> where R: Reader<'a>, Attempt to decode this message using the provided `Reader`. ### impl EncodeValue for AnyRef<'_> #### fn value_len(&self) -> Result Compute the length of this value (sans [`Tag`]+`Length` header) when encoded as ASN.1 DER. #### fn encode_value(&self, writer: &mut impl Writer) -> Result<(), Error> Encode value (sans [`Tag`]+`Length` header) as ASN.1 DER using the provided `Writer`. #### fn header(&self) -> Result where Self: Tagged, Get the `Header` used to encode this value. ### impl<'a> From<&'a Any> for AnyRef<'a> #### fn from(any: &'a Any) -> AnyRef<'a> Converts to this type from the input type. ### impl<'a> From<&'a Ia5String> for AnyRef<'a> #### fn from(international_string: &'a Ia5String) -> AnyRef<'a> Converts to this type from the input type. ### impl<'a> From<&'a ObjectIdentifier> for AnyRef<'a> #### fn from(oid: &'a ObjectIdentifier) -> AnyRef<'a> Converts to this type from the input type. ### impl<'a> From<&'a PrintableString> for AnyRef<'a> #### fn from(printable_string: &'a PrintableString) -> AnyRef<'a> Converts to this type from the input type. ### impl<'a> From<&'a TeletexString> for AnyRef<'a> #### fn from(teletex_string: &'a TeletexString) -> AnyRef<'a> Converts to this type from the input type. ### impl<'a> From<()> for AnyRef<'a> #### fn from(_: ()) -> AnyRef<'a> Converts to this type from the input type. ### impl<'a> From> for AnyRef<'a> #### fn from(internationalized_string: Ia5StringRef<'a>) -> AnyRef<'a> Converts to this type from the input type. ### impl<'a> From for AnyRef<'a> #### fn from(_: Null) -> AnyRef<'a> Converts to this type from the input type. ### impl<'a> From> for AnyRef<'a> #### fn from(octet_string: OctetStringRef<'a>) -> AnyRef<'a> Converts to this type from the input type. ### impl<'a> From> for AnyRef<'a> #### fn from(printable_string: PrintableStringRef<'a>) -> AnyRef<'a> Converts to this type from the input type. ### impl<'a> From> for AnyRef<'a> #### fn from(teletex_string: TeletexStringRef<'a>) -> AnyRef<'a> Converts to this type from the input type. ``` -------------------------------- ### Get the number of elements in SetOf Source: https://docs.rs/ed25519-dalek/2.2.0/ed25519_dalek/pkcs8/spki/der/asn1/struct.SetOf.html Returns the total number of elements currently stored in the SetOf. ```rust pub fn len(&self) -> usize ``` -------------------------------- ### Signature Creation and Conversion Source: https://docs.rs/ed25519-dalek/2.2.0/ed25519_dalek/struct.Signature.html Demonstrates creating a Signature from byte arrays and converting it to different representations. ```APIDOC ## Signature Creation and Conversion This section covers methods for creating `Signature` objects from byte arrays and converting them to various formats. ### `impl From<&[u8; 64]> for Signature` #### `fn from(bytes: &[u8; 64]) -> Signature` Converts a 64-byte array slice into a `Signature`. ### `impl From<[u8; 64]> for Signature` #### `fn from(bytes: [u8; 64]) -> Signature` Converts a 64-byte array into a `Signature`. ### `impl TryFrom<&[u8]> for Signature` #### `type Error = Error` The error type returned during conversion. #### `fn try_from(bytes: &[u8]) -> Result` Attempts to convert a byte slice into a `Signature`. Returns an error if the slice is not the correct length. ### `impl SignatureEncoding for Signature` #### `type Repr = [u8; 64]` Defines the byte representation of a signature as a 64-byte array. #### `fn to_bytes(&self) -> [u8; 64]` Encodes the signature into its 64-byte array representation. #### `fn to_vec(&self) -> Vec` Encodes the signature into a byte vector. #### `fn encoded_len(&self) -> usize` Returns the length of the signature when encoded as bytes. ``` -------------------------------- ### Get Ia5StringRef Header Source: https://docs.rs/ed25519-dalek/2.2.0/ed25519_dalek/pkcs8/spki/der/asn1/struct.Ia5StringRef.html Implements the EncodeValue trait to retrieve the ASN.1 Header for encoding an Ia5StringRef. ```rust fn header(&self) -> Result where Self: Tagged, ``` -------------------------------- ### impl TryFrom<&KeypairBytes> for SigningKey Source: https://docs.rs/ed25519-dalek/2.2.0/ed25519_dalek/pkcs8/struct.KeypairBytes.html Attempts to convert a reference to KeypairBytes into a SigningKey. ```APIDOC ## impl TryFrom<&KeypairBytes> for SigningKey ### type Error = Error ### fn try_from(pkcs8_key: &KeypairBytes) -> Result **Description:** Performs the conversion. **Parameters:** * `pkcs8_key`: A reference to a `KeypairBytes` instance. **Returns:** A `Result` containing a `SigningKey` on success, or an `Error` on failure. ``` -------------------------------- ### Rust BitString: Get Bit Length Source: https://docs.rs/ed25519-dalek/2.2.0/ed25519_dalek/pkcs8/spki/der/asn1/struct.BitString.html Calculates and returns the length of this `BIT STRING` in bits. ```rust pub fn bit_len(&self) -> usize; ``` -------------------------------- ### CloneToUninit Source: https://docs.rs/ed25519-dalek/2.2.0/ed25519_dalek/pkcs8/spki/der/asn1/struct.SetOfIter.html Provides a method to clone data into an uninitialized memory location. This is an experimental, nightly-only API. ```APIDOC ## unsafe fn clone_to_uninit(&self, dest: *mut u8) ### Description Performs copy-assignment from `self` to `dest`. ### Method `clone_to_uninit` ### Parameters #### Path Parameters - `self` (*mut T) - Required - The source value to clone. - `dest` (*mut u8) - Required - A pointer to the destination memory location. ### Note This is a nightly-only experimental API. ``` -------------------------------- ### Unwrap Ok value Source: https://docs.rs/ed25519-dalek/2.2.0/ed25519_dalek/pkcs8/spki/der/type.Result.html Returns the contained Ok value, consuming the Result. This is a basic usage example. ```rust let x: Result = Ok(2); assert_eq!(x.unwrap(), 2); ``` -------------------------------- ### Get Offset Source: https://docs.rs/ed25519-dalek/2.2.0/ed25519_dalek/pkcs8/spki/der/struct.PemReader.html Returns the offset within the original input stream. This can be useful for tracking progress or debugging. ```rust fn offset(&self) -> Length ``` -------------------------------- ### TryFrom for Document Source: https://docs.rs/ed25519-dalek/2.2.0/ed25519_dalek/pkcs8/struct.Document.html Converts an owned SubjectPublicKeyInfo into a Document. This consumes the original SubjectPublicKeyInfo, which can be efficient if the original is no longer needed. ```APIDOC ## TryFrom> for Document ### Description Performs the conversion from an owned `SubjectPublicKeyInfo` into a `Document`. ### Method `try_from` ### Parameters - **spki** (`SubjectPublicKeyInfo`) - The subject public key info to convert. ### Response - **Result** - A `Result` containing either the converted `Document` or an `Error` if the conversion fails. ``` -------------------------------- ### from (EdwardsPoint) Source: https://docs.rs/ed25519-dalek/2.2.0/ed25519_dalek/struct.VerifyingKey.html Converts an EdwardsPoint into a VerifyingKey. ```APIDOC ## from (EdwardsPoint) ### Description Converts to this type from the input type. ### Method `fn` ### Parameters #### Path Parameters - **point** (`EdwardsPoint`) - Required - The EdwardsPoint to convert. ### Returns `VerifyingKey` - The VerifyingKey derived from the EdwardsPoint. ``` -------------------------------- ### Get PemWriter Type Label Source: https://docs.rs/ed25519-dalek/2.2.0/ed25519_dalek/pkcs8/spki/der/struct.PemWriter.html Retrieves the PEM label that will be used for the encapsulation boundaries of the PEM document. ```rust pub fn type_label(&self) -> &'static str ``` -------------------------------- ### Get Current Write Position Source: https://docs.rs/ed25519-dalek/2.2.0/ed25519_dalek/pkcs8/spki/der/pem/type.Base64Encoder.html Retrieves the current position of the write cursor within the output buffer. ```rust pub fn position(&self) -> usize ``` -------------------------------- ### from Source: https://docs.rs/ed25519-dalek/2.2.0/ed25519_dalek/pkcs8/struct.ObjectIdentifier.html Creates a new instance of the type from an existing instance. This is an identity conversion. ```APIDOC ## fn from(t: T) -> T ### Description Returns the argument unchanged. ### Parameters #### Path Parameters - **t** (T) - Required - The value to convert. ``` -------------------------------- ### Get Tag Octet Encoding Source: https://docs.rs/ed25519-dalek/2.2.0/ed25519_dalek/pkcs8/spki/der/enum.Tag.html The `octet` method returns the single-byte octet encoding for a given `Tag`. ```rust pub fn octet(self) -> u8 ``` -------------------------------- ### TryFrom<&PublicKeyBytes> for VerifyingKey Source: https://docs.rs/ed25519-dalek/2.2.0/ed25519_dalek/struct.VerifyingKey.html Converts a reference to PublicKeyBytes into a VerifyingKey. This is available only when the 'pkcs8' crate feature is enabled. ```APIDOC ## impl TryFrom<&PublicKeyBytes> for VerifyingKey Available on **crate feature`pkcs8`** only. ### type Error = Error The type returned in the event of a conversion error. ### fn try_from(pkcs8_key: &PublicKeyBytes) -> Result Performs the conversion. ``` -------------------------------- ### Get Tag Number Source: https://docs.rs/ed25519-dalek/2.2.0/ed25519_dalek/pkcs8/spki/der/enum.Tag.html The `number` method returns the `TagNumber`, which represents the lower 6 bits of the tag. ```rust pub fn number(self) -> TagNumber ``` -------------------------------- ### VerifyingKey Methods Source: https://docs.rs/ed25519-dalek/2.2.0/ed25519_dalek/struct.VerifyingKey.html Provides documentation for the public methods of the VerifyingKey struct, including byte conversions, signature verification, and context-based operations. ```APIDOC ## `VerifyingKey` Struct An ed25519 public key. ### Note The `Eq` and `Hash` impls here use the compressed Edwards y encoding, _not_ the algebraic representation. This means if this `VerifyingKey` is non-canonically encoded, it will be considered unequal to the other equivalent encoding, despite the two representing the same point. More encoding details can be found here. If you want to make sure that signatures produced with respects to those sorts of public keys are rejected, use `VerifyingKey::verify_strict`. ## Implementations ### `impl VerifyingKey` #### `pub fn to_bytes(&self) -> [u8; 32]` Convert this public key to a byte array. #### `pub fn as_bytes(&self) -> &[u8; 32]` View this public key as a byte array. #### `pub fn from_bytes(bytes: &[u8; 32]) -> Result` Construct a `VerifyingKey` from a slice of bytes. Verifies the point is valid under ZIP-215 rules. RFC 8032 / NIST point validation criteria are currently unsupported (see dalek-cryptography/curve25519-dalek#626). ##### Example ``` use ed25519_dalek::VerifyingKey; use ed25519_dalek::PUBLIC_KEY_LENGTH; use ed25519_dalek::SignatureError; let public_key_bytes: [u8; PUBLIC_KEY_LENGTH] = [ 215, 90, 152, 1, 130, 177, 10, 183, 213, 75, 254, 211, 201, 100, 7, 58, 14, 225, 114, 243, 218, 166, 35, 37, 175, 2, 26, 104, 247, 7, 81, 26]; let public_key = VerifyingKey::from_bytes(&public_key_bytes)?; ``` ##### Returns A `Result` whose okay value is an EdDSA `VerifyingKey` or whose error value is a `SignatureError` describing the error that occurred. #### `pub fn with_context<'k, 'v>( &'k self, context_value: &'v [u8], ) -> Result, SignatureError>` Available on **crate feature`digest`** only. Create a verifying context that can be used for Ed25519ph with `DigestVerifier`. #### `pub fn is_weak(&self) -> bool` Returns whether this is a _weak_ public key, i.e., if this public key has low order. A weak public key can be used to generate a signature that’s valid for almost every message. `Self::verify_strict` denies weak keys, but if you want to check for this property before verification, then use this method. #### `pub fn verify_prehashed( &self, prehashed_message: MsgDigest, context: Option<&[u8]>, signature: &Signature, ) -> Result<(), SignatureError>` where MsgDigest: Digest, Available on **crate feature`digest`** only. Verify a `signature` on a `prehashed_message` using the Ed25519ph algorithm. ##### Inputs * `prehashed_message` is an instantiated hash digest with 512-bits of output which has had the message to be signed previously fed into its state. * `context` is an optional context string, up to 255 bytes inclusive, which may be used to provide additional domain separation. If not set, this will default to an empty string. * `signature` is a purported Ed25519ph signature on the `prehashed_message`. ##### Returns Returns `true` if the `signature` was a valid signature created by this `SigningKey` on the `prehashed_message`. ##### Note The RFC only permits SHA-512 to be used for prehashing, i.e., `MsgDigest = Sha512`. This function technically works, and is probably safe to use, with any secure hash function with 512-bit digests, but anything outside of SHA-512 is NOT specification-compliant. We expose `crate::Sha512` for user convenience. #### `pub fn verify_strict( &self, message: &[u8], signature: &Signature, ) -> Result<(), SignatureError>` Strictly verify a signature on a message with this keypair’s public key. ``` -------------------------------- ### CloneToUninit Implementation (Nightly) Source: https://docs.rs/ed25519-dalek/2.2.0/ed25519_dalek/pkcs8/spki/der/struct.Error.html Performs copy-assignment from self to an uninitialized destination. This is an experimental, nightly-only API. ```rust unsafe fn clone_to_uninit(&self, dest: *mut u8) ``` -------------------------------- ### tag(&self) -> Tag Source: https://docs.rs/ed25519-dalek/2.2.0/ed25519_dalek/pkcs8/spki/der/asn1/struct.PrintableString.html Gets the ASN.1 tag that this type is encoded with. This is part of the `Tagged` trait implementation. ```APIDOC ## fn tag(&self) -> Tag ### Description Get the ASN.1 tag that this type is encoded with. ### Method tag ### Parameters - **self** (*&Self*) - The instance to get the tag from. ### Response - **Success Response**: `Tag` - The ASN.1 tag associated with the type. ``` -------------------------------- ### by_ref Source: https://docs.rs/ed25519-dalek/2.2.0/ed25519_dalek/type.Sha512.html Creates a reference adapter for the CoreWrapper's `Write` implementation. This allows mutable borrowing of the writer. ```APIDOC ## by_ref ### Description Creates a “by reference” adapter for this instance of `Write`. ### Method `by_ref(&mut self) -> &mut Self` ### Response #### Success Response * **&mut Self** - A mutable reference to the writer. ``` -------------------------------- ### Get a specific arc of ObjectIdentifier Source: https://docs.rs/ed25519-dalek/2.2.0/ed25519_dalek/pkcs8/spki/der/asn1/struct.ObjectIdentifier.html Retrieve the arc (integer identifier) at a specific index within the ObjectIdentifier. ```rust pub fn arc(&self, index: usize) -> Option ``` -------------------------------- ### Get Minimum of Two Any Instances Source: https://docs.rs/ed25519-dalek/2.2.0/ed25519_dalek/pkcs8/spki/der/asn1/struct.Any.html Returns the minimum of two `Any` instances. This is part of the `Ord` trait implementation. ```rust fn min(self, other: Self) -> Self ``` -------------------------------- ### Try convert from PrivateKeyInfo reference Source: https://docs.rs/ed25519-dalek/2.2.0/ed25519_dalek/pkcs8/spki/der/struct.SecretDocument.html Attempts to convert a reference to `PrivateKeyInfo` into a `SecretDocument`. Returns an error if the conversion fails. ```rust type Error = Error; fn try_from(private_key: &PrivateKeyInfo<'_>) -> Result ``` -------------------------------- ### try_from<&[u8]> Source: https://docs.rs/ed25519-dalek/2.2.0/ed25519_dalek/struct.SigningKey.html Attempts to create a SigningKey from a byte slice. Returns a `Result` containing either the `SigningKey` or a `SignatureError` if the conversion fails. ```APIDOC ## try_from<&[u8]> ### Description Performs the conversion. ### Method `try_from(bytes: &[u8]) -> Result` ### Error Type `type Error = Error;` ``` -------------------------------- ### Get Maximum of Two Any Instances Source: https://docs.rs/ed25519-dalek/2.2.0/ed25519_dalek/pkcs8/spki/der/asn1/struct.Any.html Returns the maximum of two `Any` instances. This is part of the `Ord` trait implementation. ```rust fn max(self, other: Self) -> Self ``` -------------------------------- ### TryInto Implementation Source: https://docs.rs/ed25519-dalek/2.2.0/ed25519_dalek/pkcs8/spki/der/struct.DateTime.html Enables attempting to convert into another type. ```APIDOC ## TryInto Implementation ### type Error = >::Error **Description**: The type returned in the event of a conversion error. ### fn try_into(self) -> Result>::Error> **Description**: Performs the conversion. ### Method `try_into()` ### Returns - `Result>::Error>`: A `Result` containing the converted value or an error. ``` -------------------------------- ### Iterator enumerate() Method Source: https://docs.rs/ed25519-dalek/2.2.0/ed25519_dalek/pkcs8/spki/der/oid/struct.Arcs.html Creates an iterator that yields pairs of (index, element), where index starts at 0. ```rust fn enumerate(self) -> Enumerate where Self: Sized, ``` -------------------------------- ### from (VerifyingKey to PublicKeyBytes) Source: https://docs.rs/ed25519-dalek/2.2.0/ed25519_dalek/struct.VerifyingKey.html Converts a VerifyingKey into PublicKeyBytes. ```APIDOC ## from (VerifyingKey to PublicKeyBytes) ### Description Converts to this type from the input type. ### Method `fn` ### Parameters #### Path Parameters - **verifying_key** (`VerifyingKey`) - Required - The VerifyingKey to convert. ### Returns `PublicKeyBytes` - The PublicKeyBytes representation. ```