Class CmcePublicKeySpec

java.lang.Object
zeroecho.core.alg.cmce.CmcePublicKeySpec
All Implemented Interfaces:
AlgorithmKeySpec

public final class CmcePublicKeySpec extends Object implements AlgorithmKeySpec

Classic McEliece (CMCE) public key specification

Wraps a CMCE public key in X.509 (DER) encoding. This spec is used to import or serialize public keys into the ZeroEcho SPI.

Instances are immutable. The internal byte array is cloned on construction and on every accessor to prevent accidental mutation.

Marshalling

Example:

// Wrap an existing X.509-encoded public key
CmcePublicKeySpec spec = new CmcePublicKeySpec(x509Bytes);

// Serialize to PairSeq for storage or transport
PairSeq encoded = CmcePublicKeySpec.marshal(spec);

// Reconstruct later
CmcePublicKeySpec restored = CmcePublicKeySpec.unmarshal(encoded);
Since:
1.0
  • Constructor Details

    • CmcePublicKeySpec

      public CmcePublicKeySpec(byte[] x509Der)
      Creates a new specification from an X.509-encoded CMCE public key.

      The input is defensively copied.

      Parameters:
      x509Der - DER-encoded X.509 public key
      Throws:
      NullPointerException - if x509Der is null
  • Method Details

    • x509

      public byte[] x509()
      Returns a defensive copy of the X.509 bytes.
      Returns:
      a fresh copy of the underlying X.509 encoding
    • marshal

      public static PairSeq marshal(CmcePublicKeySpec spec)
      Serializes the given public key spec into a PairSeq.

      The X.509 bytes are Base64-encoded (without padding) and stored under the key "x509.b64". The type tag "CmcePublicKeySpec" is also included.

      Parameters:
      spec - the spec to serialize
      Returns:
      a PairSeq containing type and Base64-encoded key
      Throws:
      NullPointerException - if spec is null
    • unmarshal

      public static CmcePublicKeySpec unmarshal(PairSeq p)
      Deserializes a CmcePublicKeySpec from a PairSeq.

      The method scans for a key named "x509.b64", decodes its value from Base64, and reconstructs the spec.

      Parameters:
      p - PairSeq containing serialized fields
      Returns:
      reconstructed CmcePublicKeySpec
      Throws:
      IllegalArgumentException - if no "x509.b64" field is found
    • toString

      public String toString()
      Returns a diagnostic string with the length of the encoded key.

      The output is safe to log; it does not include key material.

      Overrides:
      toString in class Object
      Returns:
      a string in the form CmcePublicKeySpec[len=N]