Class ProductDigest

  • All Implemented Interfaces:
    ProductHandler

    public class ProductDigest
    extends java.lang.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 Detail

      • CHARSET

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

        public static final java.lang.String MESSAGE_DIGEST_ALGORITHM
        Algorithm used when generating product digest.
        See Also:
        Constant Field Values
      • MESSAGE_DIGEST_V2_ALGORITHM

        public static final java.lang.String MESSAGE_DIGEST_V2_ALGORITHM
        v2 digest algorithm
        See Also:
        Constant Field Values
    • Constructor Detail

      • ProductDigest

        protected ProductDigest​(CryptoUtils.Version version)
                         throws java.security.NoSuchAlgorithmException
        Construct a new ProductDigest.
        Parameters:
        version - signature version
        Throws:
        java.security.NoSuchAlgorithmException - if not SHA1 or SHA-256
    • Method Detail

      • digestProduct

        public static byte[] digestProduct​(Product product)
                                    throws java.lang.Exception
        A convenience method that generates a product digest.
        Parameters:
        product - the product to digest
        Returns:
        the computed digest.
        Throws:
        java.lang.Exception - if errors occur while digesting product.
      • digestProduct

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

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

        public void onBeginProduct​(ProductId id,
                                   java.lang.String status,
                                   java.net.URL trackerURL)
                            throws java.lang.Exception
        Digest the id, update time, status, and URL.
        Specified by:
        onBeginProduct in interface ProductHandler
        Parameters:
        id - which product.
        status - the product's status.
        trackerURL - a location to send status updates.
        Throws:
        java.lang.Exception - if error occurs
      • onContent

        public void onContent​(ProductId id,
                              java.lang.String path,
                              Content content)
                       throws java.lang.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:
        java.lang.Exception - if error occurs
      • onEndProduct

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

        public void onLink​(ProductId id,
                           java.lang.String relation,
                           java.net.URI href)
                    throws java.lang.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:
        java.lang.Exception - if error occurs
      • onProperty

        public void onProperty​(ProductId id,
                               java.lang.String name,
                               java.lang.String value)
                        throws java.lang.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:
        java.lang.Exception - if error occurs
      • onSignatureVersion

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

        public void onSignature​(ProductId id,
                                java.lang.String signature)
                         throws java.lang.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:
        java.lang.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​(java.lang.String[] args)
                         throws java.lang.Exception
        CLI access into ProductDigest
        Parameters:
        args - CLI Args
        Throws:
        java.lang.Exception - if error occurs