Class DigestAlgorithm

java.lang.Object
io.ocfl.api.model.DigestAlgorithm
Direct Known Subclasses:
SizeDigestAlgorithm, StandardDigestAlgorithm

public abstract class DigestAlgorithm extends Object
Maps OCFL defined digest algorithms to their Java names. Java does not include built-in implementations for all of the algorithms, using a 3rd party provider, such as BouncyCastle, is necessary for some, such as blake2b. New algorithms should be registered in the DigestAlgorithmRegistry.
  • Constructor Details

    • DigestAlgorithm

      protected DigestAlgorithm(String ocflName, String javaStandardName)
  • Method Details

    • getMessageDigest

      public abstract MessageDigest getMessageDigest()
      Creates a new MessageDigest that implements the digest algorithm
      Returns:
      new MessageDigest
    • encode

      public abstract String encode(byte[] value)
      Encodes a binary digest value into a string representation.
      Parameters:
      value - digest value
      Returns:
      the digest value as a string
    • fromOcflName

      public static DigestAlgorithm fromOcflName(String ocflName)
      Creates a DigestAlgorithm for the given OCFL name. If the name is not mapped in the DigestAlgorithmRegistry then a new object is created, but not automatically added to the registry. Newly created DigestAlgorithms are not automatically mapped to Java names.
      Parameters:
      ocflName - ocfl name of algorithm
      Returns:
      digest algorithm
    • fromOcflName

      public static DigestAlgorithm fromOcflName(String ocflName, String javaStandardName)
      Creates a DigestAlgorithm for the given OCFL name. If the name is not mapped in the DigestAlgorithmRegistry then a new object is created, but not automatically added to the registry.
      Parameters:
      ocflName - ocfl name of algorithm
      javaStandardName - the name of the algorithm in Java
      Returns:
      digest algorithm
    • getOcflName

      public String getOcflName()
      The OCFL name for the digest algorithm.
      Returns:
      standardized ocfl name for the digest algorithm
    • getJavaStandardName

      public String getJavaStandardName()
      The Java name for the digest algorithm.
      Returns:
      name of the digest algorithm in Java or null
    • hasJavaStandardName

      public boolean hasJavaStandardName()
      Indicates whether or not there is a Java mapping for the algorithm.
      Returns:
      whether or not the digest algorithm has a Java name
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object