pub fn der_encoding_from_xy_coordinates(x: &[u8], y: &[u8]) -> CryptoResult<Vec<u8>> {
    if x.len() > types::FIELD_SIZE {
        return Err(CryptoError::MalformedPublicKey {
            algorithm: AlgorithmId::EcdsaP256,
            key_bytes: Some(x.to_vec()),
            internal_error: "ECDSA x coordinate is too large".to_string(),
        });
    }

    if y.len() > types::FIELD_SIZE {
        return Err(CryptoError::MalformedPublicKey {
            algorithm: AlgorithmId::EcdsaP256,
            key_bytes: Some(y.to_vec()),
            internal_error: "ECDSA y coordinate is too large".to_string(),
        });
    }

    let mut bytes = Vec::with_capacity(1 + 2 * types::FIELD_SIZE);
    bytes.extend_from_slice(&[0x04]); // uncompressed

    // apply zero padding for x if necessary
    for _i in x.len()..types::FIELD_SIZE {
        bytes.push(0x00);
    }
    bytes.extend_from_slice(x);

    // apply zero padding for y if necessary
    for _i in y.len()..types::FIELD_SIZE {
        bytes.push(0x00);
    }
    bytes.extend_from_slice(y);
    let bytes = types::PublicKeyBytes(bytes);
    public_key_to_der(&bytes)
}
/// Parse a secp256r1 public key from the x/y affine coordinates
///
/// # Arguments
/// * `x` the x coordinate of the public point
/// * `y` the y coordinate of the public point
/// # Errors
/// * `AlgorithmNotSupported` if an error occured while invoking OpenSSL
/// * `MalformedPublicKey` if the public key could not be parsed
/// # Returns
/// The DER encoding of the public key
Parse a secp256r1 public key from the x/y affine coordinates
Parse a secp256r1 public key from the x / y affine coordinates
pub fn der_encoding_from_xy_coordinates(x: &[u8], y: &[u8]) -> CryptoResult<Vec<u8>> {
    if x.len() > types::FIELD_SIZE {
        return Err(CryptoError::MalformedPublicKey {
            algorithm: AlgorithmId::EcdsaP256,
            key_bytes: Some(x.to_vec()),
            internal_error: "ECDSA x coordinate is too large".to_string(),
        });
    }
    if y.len() > types::FIELD_SIZE {
        return Err(CryptoError::MalformedPublicKey {
            algorithm: AlgorithmId::EcdsaP256,
            key_bytes: Some(y.to_vec()),
            internal_error: "ECDSA y coordinate is too large".to_string(),
        });
    }
    let mut bytes = Vec::with_capacity(1 + 2 * types::FIELD_SIZE);
    bytes.extend_from_slice(&[0x04]); // uncompressed
    // apply zero padding for x if necessary
    for _i in x.len()..types::FIELD_SIZE {
        bytes.push(0x00);
    }
    bytes.extend_from_slice(x);
    // apply zero padding for y if necessary
    for _i in y.len()..types::FIELD_SIZE {
        bytes.push(0x00);
    }
    bytes.extend_from_slice(y);
    let bytes = types::PublicKeyBytes(bytes);
    public_key_to_der(&bytes)
}
pub fn der_encoding_from_xy_coordinates ( x : & [ u8 ] , y : & [ u8 ] ) -> CryptoResult < Vec < u8 > > { if x . len ( ) > types :: FIELD_SIZE { return Err ( CryptoError :: MalformedPublicKey { algorithm : AlgorithmId :: EcdsaP256 , key_bytes : Some ( x . to_vec ( ) ) , internal_error : " " . to_string ( ) , } ) ; } if y . len ( ) > types :: FIELD_SIZE { return Err ( CryptoError :: MalformedPublicKey { algorithm : AlgorithmId :: EcdsaP256 , key_bytes : Some ( y . to_vec ( ) ) , internal_error : " " . to_string ( ) , } ) ; } let mut bytes = Vec :: with_capacity ( 1 + 2 * types :: FIELD_SIZE ) ; bytes . extend_from_slice ( & [ 0x04 ] ) ; // uncompressed // apply zero padding for x if necessary for _i in x . len ( ) .. types :: FIELD_SIZE { bytes . push ( 0x00 ) ; } bytes . extend_from_slice ( x ) ; // apply zero padding for y if necessary for _i in y . len ( ) .. types :: FIELD_SIZE { bytes . push ( 0x00 ) ; } bytes . extend_from_slice ( y ) ; let bytes = types :: PublicKeyBytes ( bytes ) ; public_key_to_der ( & bytes ) }
Parse a secp256r1 public key from the x/y affine coordinates
Parse a secp256r1 public key from the x / y affine coordinates
x
&[u8]
y
&[u8]
The DER encoding of the public key
The DER encoding of the public key
x
&[u8]
y
&[u8]
errors
`AlgorithmNotSupported` if an error occured while invoking OpenSSL
`MalformedPublicKey` if the public key could not be parsed
` AlgorithmNotSupported ` if an error occured while invoking OpenSSL ` MalformedPublicKey ` if the public key could not be parsed