Expose two static fields on SecureHash for Java. (#2822)

This commit is contained in:
Chris Rankin 2018-03-15 08:59:45 +00:00 committed by GitHub
parent 27e45bc865
commit a644741819
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -82,13 +82,31 @@ sealed class SecureHash(bytes: ByteArray) : OpaqueBytes(bytes) {
/**
* A SHA-256 hash value consisting of 32 0x00 bytes.
* This field provides more intuitive access from Java.
*/
val zeroHash = SecureHash.SHA256(ByteArray(32, { 0.toByte() }))
@JvmField
val zeroHash: SHA256 = SecureHash.SHA256(ByteArray(32, { 0.toByte() }))
/**
* A SHA-256 hash value consisting of 32 0x00 bytes.
* This function is provided for API stability.
*/
@Suppress("Unused")
fun getZeroHash(): SHA256 = zeroHash
/**
* A SHA-256 hash value consisting of 32 0xFF bytes.
* This field provides more intuitive access from Java.
*/
val allOnesHash = SecureHash.SHA256(ByteArray(32, { 255.toByte() }))
@JvmField
val allOnesHash: SHA256 = SecureHash.SHA256(ByteArray(32, { 255.toByte() }))
/**
* A SHA-256 hash value consisting of 32 0xFF bytes.
* This function is provided for API stability.
*/
@Suppress("Unused")
fun getAllOnesHash(): SHA256 = allOnesHash
}
// In future, maybe SHA3, truncated hashes etc.