Class ProductDigest

java.lang.Object
gov.usgs.earthquake.product.ProductDigest
All Implemented Interfaces:
ProductHandler

public class ProductDigest extends Object implements ProductHandler
Used to generate product digests. All product attributes and content are used when generating a digest, except any existing signature, since the digest is used to generate or verify signatures. Calls to ProductOutput methods on this class must occur in identical order to generate consistent signatures. Therefore it is almost required to use the ObjectProductInput, which fulfills this requirement.
  • Field Details

    • CHARSET

      public static final Charset CHARSET
      Character set used when computing digests.
    • MESSAGE_DIGEST_ALGORITHM

      public static final String MESSAGE_DIGEST_ALGORITHM
      Algorithm used when generating product digest.
      See Also:
    • MESSAGE_DIGEST_V2_ALGORITHM

      public static final String MESSAGE_DIGEST_V2_ALGORITHM
      v2 digest algorithm
      See Also:
  • Constructor Details

  • Method Details

    • digestProduct

      public static byte[] digestProduct(Product product, CryptoUtils.Version version) throws Exception
      Parameters:
      product - A product
      version - What version of product digest
      Returns:
      A byte array of the product digest
      Throws:
      Exception - if error occurs
    • getDigest

      public byte[] getDigest()
      Returns:
      the computed digest, or null if not finished yet.
    • onBeginProduct

      public void onBeginProduct(ProductId id, String status) throws Exception
      Digest the id, update time, status, and URL.
      Specified by:
      onBeginProduct in interface ProductHandler
      Parameters:
      id - which product.
      status - the product's status.
      Throws:
      Exception - if error occurs
    • onContent

      public void onContent(ProductId id, String path, Content content) throws Exception
      Digest the path, content attributes, and content bytes.
      Specified by:
      onContent in interface ProductHandler
      Parameters:
      id - which product.
      path - path to content within product.
      content - the product content.
      Throws:
      Exception - if error occurs
    • onEndProduct

      public void onEndProduct(ProductId id) throws Exception
      Finish computing digest.
      Specified by:
      onEndProduct in interface ProductHandler
      Parameters:
      id - which product.
      Throws:
      Exception - if error occurs
    • onLink

      public void onLink(ProductId id, String relation, URI href) throws Exception
      Digest the link relation and href.
      Specified by:
      onLink in interface ProductHandler
      Parameters:
      id - which product.
      relation - how the URI is related to this product.
      href - the URI that is related to this product.
      Throws:
      Exception - if error occurs
    • onProperty

      public void onProperty(ProductId id, String name, String value) throws Exception
      Digest the property name and value.
      Specified by:
      onProperty in interface ProductHandler
      Parameters:
      id - which product.
      name - the property name.
      value - the property value.
      Throws:
      Exception - if error occurs
    • onSignatureVersion

      public void onSignatureVersion(ProductId id, CryptoUtils.Version version) throws Exception
      Don't digest signature version.
      Specified by:
      onSignatureVersion in interface ProductHandler
      Parameters:
      id - which product.
      version - product version
      Throws:
      Exception - if error occurs
    • onSignature

      public void onSignature(ProductId id, String signature) throws Exception
      Don't digest the signature.
      Specified by:
      onSignature in interface ProductHandler
      Parameters:
      id - which product.
      signature - the product signature, which can be verified using the ProductSigner class.
      Throws:
      Exception - if error occurs
    • onSignatureHistory

      public void onSignatureHistory(ProductId id, List<ProductSignature> signatureHistory) throws Exception
      Don't digest the signature history.
      Specified by:
      onSignatureHistory in interface ProductHandler
      Parameters:
      id - which product.
      signatureHistory - signature history of product.
      Throws:
      Exception - if error occurs
    • close

      public void close()
      Free any resources associated with this handler.
      Specified by:
      close in interface ProductHandler
    • main

      public static void main(String[] args) throws Exception
      CLI access into ProductDigest
      Parameters:
      args - CLI Args
      Throws:
      Exception - if error occurs