Class NullKey

java.lang.Object
zeroecho.core.NullKey
All Implemented Interfaces:
Serializable, Key

public final class NullKey extends Object implements Key
Sentinel Key representing the intentional absence of cryptographic key material.

NullKey satisfies APIs that require a Key reference even when no secret exists (e.g., unkeyed digests or placeholder capabilities). It contains no sensitive data and is safe to log and share.

Intended uses

  • Unkeyed operations such as DIGEST roles where keys are semantically undefined but a Key parameter is part of a common interface.
  • Testing and scaffolding where a non-null Key is required to exercise type and flow without provisioning secrets.
  • Metadata publication for capabilities that don’t depend on key material.

Security properties

  • Contains no secret; getEncoded() returns an empty byte array.
  • Algorithm and format are the literal string "NONE".
  • All instances are equal by type; prefer the INSTANCE singleton.

Thread-safety

Immutable; the singleton instance is safe to reuse across threads.
Since:
1.0
See Also:
  • Field Details

    • INSTANCE

      public static final NullKey INSTANCE
      Singleton instance for all uses where a Key is required but no key exists.

      Use this constant rather than constructing new instances. Equality for NullKey is defined by type, so all instances compare equal; the singleton avoids unnecessary allocations and clarifies intent.

  • Method Details

    • getAlgorithm

      public String getAlgorithm()
      Returns the algorithm identifier for this sentinel key.

      The value is the literal string "NONE" to signal that no real cryptographic algorithm is associated with this key.

      Specified by:
      getAlgorithm in interface Key
      Returns:
      the string "NONE"
    • getFormat

      public String getFormat()
      Returns the primary encoding format for this sentinel key.

      The value is the literal string "NONE"; getEncoded() returns an empty byte array.

      Specified by:
      getFormat in interface Key
      Returns:
      the string "NONE"
    • getEncoded

      public byte[] getEncoded()
      Returns the key in its primary encoding.

      For NullKey, this is an empty byte array because no material exists. Callers MAY rely on this to avoid special-casing unkeyed flows.

      Specified by:
      getEncoded in interface Key
      Returns:
      a new zero-length byte array
    • equals

      public boolean equals(Object obj)
      Compares this object to another for equality.

      All NullKey instances are considered equal regardless of identity; equality is defined by type rather than state. Prefer comparing against INSTANCE when intent matters, but this method ensures generic collections and caches behave as expected.

      Overrides:
      equals in class Object
      Parameters:
      obj - the reference object with which to compare
      Returns:
      true if obj is a NullKey; false otherwise
    • hashCode

      public int hashCode()
      Returns a stable hash code consistent with equals(Object).

      Derived from a fixed class-based token so that all NullKey instances hash identically, matching the type-based equality semantics.

      Overrides:
      hashCode in class Object
      Returns:
      a stable hash code value
    • toString

      public String toString()
      Returns a diagnostic string for logs and debugging.

      The returned value is the literal "NullKey". It contains no secrets and is safe for inclusion in logs and error messages.

      Overrides:
      toString in class Object
      Returns:
      the string "NullKey"