mirror of
https://github.com/pgpainless/pgpainless.git
synced 2024-12-23 03:17:58 +01:00
Update examples with new MessageMetadata class
This commit is contained in:
parent
f005885318
commit
27fd15a012
2 changed files with 30 additions and 33 deletions
|
@ -24,7 +24,7 @@ import org.pgpainless.PGPainless;
|
||||||
import org.pgpainless.algorithm.DocumentSignatureType;
|
import org.pgpainless.algorithm.DocumentSignatureType;
|
||||||
import org.pgpainless.decryption_verification.ConsumerOptions;
|
import org.pgpainless.decryption_verification.ConsumerOptions;
|
||||||
import org.pgpainless.decryption_verification.DecryptionStream;
|
import org.pgpainless.decryption_verification.DecryptionStream;
|
||||||
import org.pgpainless.decryption_verification.OpenPgpMetadata;
|
import org.pgpainless.decryption_verification.MessageMetadata;
|
||||||
import org.pgpainless.encryption_signing.EncryptionStream;
|
import org.pgpainless.encryption_signing.EncryptionStream;
|
||||||
import org.pgpainless.encryption_signing.ProducerOptions;
|
import org.pgpainless.encryption_signing.ProducerOptions;
|
||||||
import org.pgpainless.encryption_signing.SigningOptions;
|
import org.pgpainless.encryption_signing.SigningOptions;
|
||||||
|
@ -168,9 +168,9 @@ public class DecryptOrVerify {
|
||||||
decryptionStream.close(); // remember to close the stream!
|
decryptionStream.close(); // remember to close the stream!
|
||||||
|
|
||||||
// The metadata object contains information about the message
|
// The metadata object contains information about the message
|
||||||
OpenPgpMetadata metadata = decryptionStream.getResult();
|
MessageMetadata metadata = decryptionStream.getMetadata();
|
||||||
assertTrue(metadata.isEncrypted()); // message was encrypted
|
assertTrue(metadata.isEncrypted()); // message was encrypted
|
||||||
assertFalse(metadata.isVerified()); // We did not do any signature verification
|
assertFalse(metadata.isVerifiedSigned()); // We did not do any signature verification
|
||||||
|
|
||||||
// The output stream now contains the decrypted message
|
// The output stream now contains the decrypted message
|
||||||
assertEquals(PLAINTEXT, plaintextOut.toString());
|
assertEquals(PLAINTEXT, plaintextOut.toString());
|
||||||
|
@ -200,11 +200,10 @@ public class DecryptOrVerify {
|
||||||
decryptionStream.close(); // remember to close the stream to finish signature verification
|
decryptionStream.close(); // remember to close the stream to finish signature verification
|
||||||
|
|
||||||
// metadata with information on the message, like signatures
|
// metadata with information on the message, like signatures
|
||||||
OpenPgpMetadata metadata = decryptionStream.getResult();
|
MessageMetadata metadata = decryptionStream.getMetadata();
|
||||||
assertTrue(metadata.isEncrypted()); // messages was in fact encrypted
|
assertTrue(metadata.isEncrypted()); // messages was in fact encrypted
|
||||||
assertTrue(metadata.isSigned()); // message contained some signatures
|
assertTrue(metadata.isVerifiedSigned()); // the signatures were actually correct
|
||||||
assertTrue(metadata.isVerified()); // the signatures were actually correct
|
assertTrue(metadata.isVerifiedSignedBy(certificate)); // the signatures could be verified using the certificate
|
||||||
assertTrue(metadata.containsVerifiedSignatureFrom(certificate)); // the signatures could be verified using the certificate
|
|
||||||
|
|
||||||
assertEquals(PLAINTEXT, plaintextOut.toString());
|
assertEquals(PLAINTEXT, plaintextOut.toString());
|
||||||
}
|
}
|
||||||
|
@ -232,8 +231,8 @@ public class DecryptOrVerify {
|
||||||
verificationStream.close(); // remember to close the stream to finish sig verification
|
verificationStream.close(); // remember to close the stream to finish sig verification
|
||||||
|
|
||||||
// Get the metadata object for information about the message
|
// Get the metadata object for information about the message
|
||||||
OpenPgpMetadata metadata = verificationStream.getResult();
|
MessageMetadata metadata = verificationStream.getMetadata();
|
||||||
assertTrue(metadata.isVerified()); // signatures were verified successfully
|
assertTrue(metadata.isVerifiedSigned()); // signatures were verified successfully
|
||||||
// The output stream we piped to now contains the message
|
// The output stream we piped to now contains the message
|
||||||
assertEquals(PLAINTEXT, out.toString());
|
assertEquals(PLAINTEXT, out.toString());
|
||||||
}
|
}
|
||||||
|
@ -286,8 +285,8 @@ public class DecryptOrVerify {
|
||||||
verificationStream.close(); // as always, remember to close the stream
|
verificationStream.close(); // as always, remember to close the stream
|
||||||
|
|
||||||
// Metadata will confirm that the message was in fact signed
|
// Metadata will confirm that the message was in fact signed
|
||||||
OpenPgpMetadata metadata = verificationStream.getResult();
|
MessageMetadata metadata = verificationStream.getMetadata();
|
||||||
assertTrue(metadata.isVerified());
|
assertTrue(metadata.isVerifiedSigned());
|
||||||
// compare the plaintext to what we originally signed
|
// compare the plaintext to what we originally signed
|
||||||
assertArrayEquals(msg.getBytes(StandardCharsets.UTF_8), plain.toByteArray());
|
assertArrayEquals(msg.getBytes(StandardCharsets.UTF_8), plain.toByteArray());
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,7 @@ import org.pgpainless.PGPainless;
|
||||||
import org.pgpainless.algorithm.DocumentSignatureType;
|
import org.pgpainless.algorithm.DocumentSignatureType;
|
||||||
import org.pgpainless.decryption_verification.ConsumerOptions;
|
import org.pgpainless.decryption_verification.ConsumerOptions;
|
||||||
import org.pgpainless.decryption_verification.DecryptionStream;
|
import org.pgpainless.decryption_verification.DecryptionStream;
|
||||||
import org.pgpainless.decryption_verification.OpenPgpMetadata;
|
import org.pgpainless.decryption_verification.MessageMetadata;
|
||||||
import org.pgpainless.encryption_signing.EncryptionOptions;
|
import org.pgpainless.encryption_signing.EncryptionOptions;
|
||||||
import org.pgpainless.encryption_signing.EncryptionStream;
|
import org.pgpainless.encryption_signing.EncryptionStream;
|
||||||
import org.pgpainless.encryption_signing.ProducerOptions;
|
import org.pgpainless.encryption_signing.ProducerOptions;
|
||||||
|
@ -176,9 +176,9 @@ public class Encrypt {
|
||||||
decryptor.close();
|
decryptor.close();
|
||||||
|
|
||||||
// Check the metadata to see how the message was encrypted/signed
|
// Check the metadata to see how the message was encrypted/signed
|
||||||
OpenPgpMetadata metadata = decryptor.getResult();
|
MessageMetadata metadata = decryptor.getMetadata();
|
||||||
assertTrue(metadata.isEncrypted());
|
assertTrue(metadata.isEncrypted());
|
||||||
assertTrue(metadata.containsVerifiedSignatureFrom(certificateAlice));
|
assertTrue(metadata.isVerifiedSignedBy(certificateAlice));
|
||||||
assertEquals(message, plaintext.toString());
|
assertEquals(message, plaintext.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -281,10 +281,8 @@ public class Encrypt {
|
||||||
decryptor.close();
|
decryptor.close();
|
||||||
|
|
||||||
// Check the metadata to see how the message was encrypted/signed
|
// Check the metadata to see how the message was encrypted/signed
|
||||||
OpenPgpMetadata metadata = decryptor.getResult();
|
MessageMetadata metadata = decryptor.getMetadata();
|
||||||
assertTrue(metadata.isEncrypted());
|
assertTrue(metadata.isEncrypted());
|
||||||
assertEquals(message, plaintext.toString());
|
assertEquals(message, plaintext.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue