package x509

  1. Overview
  2. Docs

Public key DER and PEM encoding and decoding

Public keys as specified in PKCS 8 are supported in this module.

type t = [
  1. | `RSA of Mirage_crypto_pk.Rsa.pub
  2. | `ED25519 of Mirage_crypto_ec.Ed25519.pub
  3. | `P224 of Mirage_crypto_ec.P224.Dsa.pub
  4. | `P256 of Mirage_crypto_ec.P256.Dsa.pub
  5. | `P384 of Mirage_crypto_ec.P384.Dsa.pub
  6. | `P521 of Mirage_crypto_ec.P521.Dsa.pub
  7. | `EC_pub of Asn.oid * Cstruct.t
]

The polymorphic variant of public keys, with PKCS 8 encoding and decoding to PEM.

val id : t -> Cstruct.t

id public_key is digest, the 160-bit `SHA1 hash of the BIT STRING subjectPublicKey (excluding tag, length, and number of unused bits) for publicKeyInfo of public_key.

RFC 5280, 4.2.1.2, variant (1)

val fingerprint : ?hash:Mirage_crypto.Hash.hash -> t -> Cstruct.t

fingerprint ?hash public_key is digest, the hash (by default SHA256) of the DER encoded public key (equivalent to openssl x509 -noout -pubkey | openssl pkey -pubin -outform DER | openssl dgst -HASH).

val pp : t Fmt.t

pp ppf pub pretty-prints the public key pub on ppf.

Decoding and encoding in ASN.1 DER and PEM format

val encode_der : t -> Cstruct.t

encode_der pk is buffer, the ASN.1 encoding of the given public key.

val decode_der : Cstruct.t -> (t, [> Rresult.R.msg ]) Rresult.result

decode_der buffer is pubkey, the public key of the ASN.1 encoded buffer.

val decode_pem : Cstruct.t -> (t, [> Rresult.R.msg ]) Rresult.result

decode_pem pem is t, where the public key of pem is extracted

val encode_pem : t -> Cstruct.t

encode_pem public_key is pem, the pem encoded public key.

OCaml

Innovation. Community. Security.