Package gov.usgs.earthquake.product
Class ProductDigest
java.lang.Object
gov.usgs.earthquake.product.ProductDigest
- All Implemented Interfaces:
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 Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
ProductDigest
(CryptoUtils.Version version) Construct a new ProductDigest. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Free any resources associated with this handler.static byte[]
digestProduct
(Product product, CryptoUtils.Version version) byte[]
static void
CLI access into ProductDigestvoid
onBeginProduct
(ProductId id, String status) Digest the id, update time, status, and URL.void
Digest the path, content attributes, and content bytes.void
Finish computing digest.void
Digest the link relation and href.void
onProperty
(ProductId id, String name, String value) Digest the property name and value.void
onSignature
(ProductId id, String signature) Don't digest the signature.void
onSignatureHistory
(ProductId id, List<ProductSignature> signatureHistory) Don't digest the signature history.void
onSignatureVersion
(ProductId id, CryptoUtils.Version version) Don't digest signature version.
-
Field Details
-
CHARSET
Character set used when computing digests. -
MESSAGE_DIGEST_ALGORITHM
Algorithm used when generating product digest.- See Also:
-
MESSAGE_DIGEST_V2_ALGORITHM
v2 digest algorithm- See Also:
-
-
Constructor Details
-
ProductDigest
Construct a new ProductDigest.- Parameters:
version
- signature version- Throws:
NoSuchAlgorithmException
- if not SHA1 or SHA-256
-
-
Method Details
-
digestProduct
- Parameters:
product
- A productversion
- 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
Digest the id, update time, status, and URL.- Specified by:
onBeginProduct
in interfaceProductHandler
- Parameters:
id
- which product.status
- the product's status.- Throws:
Exception
- if error occurs
-
onContent
Digest the path, content attributes, and content bytes.- Specified by:
onContent
in interfaceProductHandler
- Parameters:
id
- which product.path
- path to content within product.content
- the product content.- Throws:
Exception
- if error occurs
-
onEndProduct
Finish computing digest.- Specified by:
onEndProduct
in interfaceProductHandler
- Parameters:
id
- which product.- Throws:
Exception
- if error occurs
-
onLink
Digest the link relation and href.- Specified by:
onLink
in interfaceProductHandler
- 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
Digest the property name and value.- Specified by:
onProperty
in interfaceProductHandler
- Parameters:
id
- which product.name
- the property name.value
- the property value.- Throws:
Exception
- if error occurs
-
onSignatureVersion
Don't digest signature version.- Specified by:
onSignatureVersion
in interfaceProductHandler
- Parameters:
id
- which product.version
- product version- Throws:
Exception
- if error occurs
-
onSignature
Don't digest the signature.- Specified by:
onSignature
in interfaceProductHandler
- 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 interfaceProductHandler
- 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 interfaceProductHandler
-
main
CLI access into ProductDigest- Parameters:
args
- CLI Args- Throws:
Exception
- if error occurs
-