本文整理匯總了Java中java.security.DigestInputStream.on方法的典型用法代碼示例。如果您正苦於以下問題:Java DigestInputStream.on方法的具體用法?Java DigestInputStream.on怎麽用?Java DigestInputStream.on使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.security.DigestInputStream
的用法示例。
在下文中一共展示了DigestInputStream.on方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: processDigest
import java.security.DigestInputStream; //導入方法依賴的package包/類
/**
* This method allows to compute the digest of the TBSCertList
*
* @param s
* an initialized DigestInputStream
* @throws IOException
*/
public void processDigest(DigestInputStream s) throws IOException {
// We don't digest the beginning (not part of TBS)
s.on(false);
// Skip CertificateList Sequence info
consumeTagIntro(s);
// Start to digest TBS
s.on(true);
// Strip the tag and length of the TBSCertList sequence
int tag = DERUtil.readTag(s);
DERUtil.readTagNumber(s, tag);
int tbsLength = DERUtil.readLength(s);
// Read TBSCertList Content
readNbBytes(s, tbsLength);
// End digest TBS
s.on(false);
}
示例2: testRead06
import java.security.DigestInputStream; //導入方法依賴的package包/類
/**
* Test #6 for <code>read()</code> method<br>
* Test #2 for <code>on(boolean)</code> method<br>
*
* Assertion: broken <code>DigestInputStream</code>instance:
* associated <code>MessageDigest</code> not set.
* <code>read()</code> must work when digest
* functionality is off
*/
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
notes = "",
method = "read",
args = {}
)
public final void testRead06()
throws IOException {
InputStream is = new ByteArrayInputStream(myMessage);
// construct object without digest
DigestInputStream dis = new DigestInputStream(is, null);
// set digest functionality to off
dis.on(false);
// the following must pass without any exception
for (int i=0; i<MY_MESSAGE_LEN; i++) {
assertTrue((byte)dis.read() == myMessage[i]);
}
}
示例3: testRead03
import java.security.DigestInputStream; //導入方法依賴的package包/類
/**
* Test #3 for <code>read()</code> method<br>
* Test #1 for <code>on(boolean)</code> method<br>
*
* Assertion: <code>read()</code> must not update digest if it is off<br>
* Assertion: <code>on(boolean)</code> turns digest functionality on
* (if <code>true</code> passed as a parameter) or off (if <code>false</code>
* passed)
*/
public final void testRead03()
throws IOException {
for (int ii=0; ii<algorithmName.length; ii++) {
try {
MessageDigest md = MessageDigest.getInstance(algorithmName[ii]);
InputStream is = new ByteArrayInputStream(myMessage);
DigestInputStream dis = new DigestInputStream(is, md);
// turn digest off
dis.on(false);
for (int i=0; i<MY_MESSAGE_LEN; i++) {
dis.read();
}
// check that digest value has not been updated by read()
assertTrue(Arrays.equals(dis.getMessageDigest().digest(),
MDGoldenData.getDigest(algorithmName[ii]+"_NU")));
return;
} catch (NoSuchAlgorithmException e) {
// allowed failure
}
}
fail(getName() + ": no MessageDigest algorithms available - test not performed");
}
示例4: readBinary
import java.security.DigestInputStream; //導入方法依賴的package包/類
private Sha256Hash readBinary(InputStream inputStream) throws IOException {
DataInputStream dis = null;
try {
MessageDigest digest = Sha256Hash.newDigest();
DigestInputStream digestInputStream = new DigestInputStream(inputStream, digest);
dis = new DataInputStream(digestInputStream);
digestInputStream.on(false);
byte[] header = new byte[BINARY_MAGIC.length()];
dis.readFully(header);
if (!Arrays.equals(header, BINARY_MAGIC.getBytes("US-ASCII")))
throw new IOException("Header bytes did not match expected version");
int numSignatures = checkPositionIndex(dis.readInt(), MAX_SIGNATURES, "Num signatures out of range");
for (int i = 0; i < numSignatures; i++) {
byte[] sig = new byte[65];
dis.readFully(sig);
// TODO: Do something with the signature here.
}
digestInputStream.on(true);
int numCheckpoints = dis.readInt();
checkState(numCheckpoints > 0);
final int size = StoredBlock.COMPACT_SERIALIZED_SIZE;
ByteBuffer buffer = ByteBuffer.allocate(size);
for (int i = 0; i < numCheckpoints; i++) {
if (dis.read(buffer.array(), 0, size) < size)
throw new IOException("Incomplete read whilst loading checkpoints.");
StoredBlock block = StoredBlock.deserializeCompact(params, buffer);
buffer.position(0);
checkpoints.put(block.getHeader().getTimeSeconds(), block);
}
Sha256Hash dataHash = Sha256Hash.wrap(digest.digest());
log.info("Read {} checkpoints, hash is {}", checkpoints.size(), dataHash);
return dataHash;
} catch (ProtocolException e) {
throw new IOException(e);
} finally {
if (dis != null) dis.close();
inputStream.close();
}
}
示例5: testRead03
import java.security.DigestInputStream; //導入方法依賴的package包/類
/**
* Test #3 for <code>read()</code> method<br>
* Test #1 for <code>on(boolean)</code> method<br>
*
* Assertion: <code>read()</code> must not update digest if it is off<br>
* Assertion: <code>on(boolean)</code> turns digest functionality on
* (if <code>true</code> passed as a parameter) or off (if <code>false</code>
* passed)
*/
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
notes = "",
method = "read",
args = {}
)
public final void testRead03()
throws IOException {
for (int ii=0; ii<algorithmName.length; ii++) {
try {
MessageDigest md = MessageDigest.getInstance(algorithmName[ii]);
InputStream is = new ByteArrayInputStream(myMessage);
DigestInputStream dis = new DigestInputStream(is, md);
// turn digest off
dis.on(false);
for (int i=0; i<MY_MESSAGE_LEN; i++) {
dis.read();
}
// check that digest value has not been updated by read()
assertTrue(Arrays.equals(dis.getMessageDigest().digest(),
MDGoldenData.getDigest(algorithmName[ii]+"_NU")));
return;
} catch (NoSuchAlgorithmException e) {
// allowed failure
}
}
fail(getName() + ": no MessageDigest algorithms available - test not performed");
}
示例6: testReadbyteArrayintint05
import java.security.DigestInputStream; //導入方法依賴的package包/類
/**
* Test #5 for <code>read(byte[],int,int)</code> method<br>
*
* Assertion: returns the number of bytes read<br>
*
* Assertion: put bytes read into specified array at specified offset<br>
*
* Assertion: does not update associated digest if
* digest functionality is off<br>
*/
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
method = "read",
args = {byte[].class, int.class, int.class}
)
public final void testReadbyteArrayintint05()
throws IOException {
// check precondition
assertEquals(0, MY_MESSAGE_LEN % CHUNK_SIZE);
for (int ii=0; ii<algorithmName.length; ii++) {
try {
MessageDigest md = MessageDigest.getInstance(algorithmName[ii]);
InputStream is = new ByteArrayInputStream(myMessage);
DigestInputStream dis = new DigestInputStream(is, md);
byte[] bArray = new byte[MY_MESSAGE_LEN];
// turn digest off
dis.on(false);
for (int i=0; i<MY_MESSAGE_LEN/CHUNK_SIZE; i++) {
dis.read(bArray, i*CHUNK_SIZE, CHUNK_SIZE);
}
// check that digest has not been updated
assertTrue(Arrays.equals(dis.getMessageDigest().digest(),
MDGoldenData.getDigest(algorithmName[ii]+"_NU")));
return;
} catch (NoSuchAlgorithmException e) {
// allowed failure
}
}
fail(getName() + ": no MessageDigest algorithms available - test not performed");
}
示例7: testRead06
import java.security.DigestInputStream; //導入方法依賴的package包/類
/**
* Test #6 for <code>read()</code> method<br>
* Test #2 for <code>on(boolean)</code> method<br>
*
* Assertion: broken <code>DigestInputStream</code>instance:
* associated <code>MessageDigest</code> not set.
* <code>read()</code> must work when digest
* functionality is off
*/
public final void testRead06()
throws IOException {
InputStream is = new ByteArrayInputStream(myMessage);
// construct object without digest
DigestInputStream dis = new DigestInputStream(is, null);
// set digest functionality to off
dis.on(false);
// the following must pass without any exception
for (int i=0; i<MY_MESSAGE_LEN; i++) {
assertTrue((byte)dis.read() == myMessage[i]);
}
}
示例8: testReadbyteArrayintint05
import java.security.DigestInputStream; //導入方法依賴的package包/類
/**
* Test #5 for <code>read(byte[],int,int)</code> method<br>
*
* Assertion: returns the number of bytes read<br>
*
* Assertion: put bytes read into specified array at specified offset<br>
*
* Assertion: does not update associated digest if
* digest functionality is off<br>
*/
public final void testReadbyteArrayintint05()
throws IOException {
// check precondition
assertEquals(0, MY_MESSAGE_LEN % CHUNK_SIZE);
for (int ii=0; ii<algorithmName.length; ii++) {
try {
MessageDigest md = MessageDigest.getInstance(algorithmName[ii]);
InputStream is = new ByteArrayInputStream(myMessage);
DigestInputStream dis = new DigestInputStream(is, md);
byte[] bArray = new byte[MY_MESSAGE_LEN];
// turn digest off
dis.on(false);
for (int i=0; i<MY_MESSAGE_LEN/CHUNK_SIZE; i++) {
dis.read(bArray, i*CHUNK_SIZE, CHUNK_SIZE);
}
// check that digest has not been updated
assertTrue(Arrays.equals(dis.getMessageDigest().digest(),
MDGoldenData.getDigest(algorithmName[ii]+"_NU")));
return;
} catch (NoSuchAlgorithmException e) {
// allowed failure
}
}
fail(getName() + ": no MessageDigest algorithms available - test not performed");
}
示例9: testOn
import java.security.DigestInputStream; //導入方法依賴的package包/類
/**
* Test for <code>on()</code> method<br>
* Assertion: turns digest functionality on or off
*/
public final void testOn() throws IOException {
for (int ii=0; ii<algorithmName.length; ii++) {
try {
MessageDigest md = MessageDigest.getInstance(algorithmName[ii]);
InputStream is = new ByteArrayInputStream(myMessage);
DigestInputStream dis = new DigestInputStream(is, md);
// turn digest off
dis.on(false);
for (int i=0; i<MY_MESSAGE_LEN-1; i++) {
dis.read();
}
// turn digest on
dis.on(true);
// read remaining byte
dis.read();
byte[] digest = dis.getMessageDigest().digest();
// check that digest value has been
// updated by the last read() call
assertFalse(
Arrays.equals(digest,MDGoldenData.getDigest(algorithmName[ii])) ||
Arrays.equals(digest,MDGoldenData.getDigest(algorithmName[ii]+"_NU")));
return;
} catch (NoSuchAlgorithmException e) {
// allowed failure
}
}
fail(getName() + ": no MessageDigest algorithms available - test not performed");
}
示例10: testOn
import java.security.DigestInputStream; //導入方法依賴的package包/類
/**
* Test for <code>on()</code> method<br>
* Assertion: turns digest functionality on or off
*/
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "",
method = "on",
args = {boolean.class}
)
public final void testOn() throws IOException {
for (int ii=0; ii<algorithmName.length; ii++) {
try {
MessageDigest md = MessageDigest.getInstance(algorithmName[ii]);
InputStream is = new ByteArrayInputStream(myMessage);
DigestInputStream dis = new DigestInputStream(is, md);
// turn digest off
dis.on(false);
for (int i=0; i<MY_MESSAGE_LEN-1; i++) {
dis.read();
}
// turn digest on
dis.on(true);
// read remaining byte
dis.read();
byte[] digest = dis.getMessageDigest().digest();
// check that digest value has been
// updated by the last read() call
assertFalse(
Arrays.equals(digest,MDGoldenData.getDigest(algorithmName[ii])) ||
Arrays.equals(digest,MDGoldenData.getDigest(algorithmName[ii]+"_NU")));
return;
} catch (NoSuchAlgorithmException e) {
// allowed failure
}
}
fail(getName() + ": no MessageDigest algorithms available - test not performed");
}