Skip to main content

decode

Function decode 

Source
pub fn decode(input: &[u8]) -> Option<EcPrivateKey>
Expand description

Decode a DER ECPrivateKey blob.

Validates:

  • outer SEQUENCE with no trailing bytes;
  • version == 1;
  • privateKey is a 32-byte OCTET STRING (SM2’s curve has 256-bit scalars; oversize/undersize is malformed);
  • if present, [0] parameters is namedCurve = sm2p256v1 only;
  • if present, [1] publicKey is a 65-byte uncompressed point that decodes successfully (on-curve, not identity).

Returns None for any malformed input.