-
Notifications
You must be signed in to change notification settings - Fork 122
ParsedCiphertext throws an error if it is not complete #119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 7 commits
b3df03b
62b36df
5ebec3e
b9b64ed
e326d12
85da442
3aad539
da0938b
a0c93ec
db1fc9d
39883c2
9590174
ece073c
27a4459
fb23a71
5e5c2db
ff29cee
566975a
7b7b703
d89ff00
22c3e7d
3dd630c
07f60a6
ad9f4af
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package com.amazonaws.encryptionsdk; | ||
|
||
import com.amazonaws.encryptionsdk.internal.StaticMasterKey; | ||
import com.amazonaws.encryptionsdk.model.CiphertextHeaders; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import com.amazonaws.encryptionsdk.exception.BadCiphertextException; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import static org.mockito.Mockito.spy; | ||
|
||
public class ParsedCiphertextTest extends CiphertextHeaders { | ||
final byte[] ciphertext_ = {0}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is "ciphertext" that we expect to fail being parsed, so let's move this into the incompleteCiphertext test. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed. Also, please improve the name of this variable and ensure that you handle incomplete ciphertexts which are longer than a single zero byte (such as only a single byte short). |
||
|
||
final int byteSize = 0; | ||
lavaleri marked this conversation as resolved.
Show resolved
Hide resolved
|
||
final int frameSize = 0; | ||
|
||
private StaticMasterKey masterKeyProvider; | ||
private AwsCrypto encryptionClient_; | ||
|
||
@Before | ||
public void init() { | ||
masterKeyProvider = spy(new StaticMasterKey("testmaterial")); | ||
|
||
encryptionClient_ = new AwsCrypto(); | ||
encryptionClient_.setEncryptionAlgorithm(CryptoAlgorithm.ALG_AES_128_GCM_IV12_TAG16_HKDF_SHA256); | ||
} | ||
|
||
@Test | ||
public void completeCiphertext() { | ||
final byte[] plaintextBytes = new byte[byteSize]; | ||
|
||
final Map<String, String> encryptionContext = new HashMap<String, String>(1); | ||
encryptionContext.put("ENC1", "ParsedCiphertext test with %d" + byteSize); | ||
|
||
encryptionClient_.setEncryptionFrameSize(frameSize); | ||
|
||
final byte[] cipherText = encryptionClient_.encryptData( | ||
masterKeyProvider, | ||
plaintextBytes, | ||
encryptionContext).getResult(); | ||
ParsedCiphertext pCt = new ParsedCiphertext(cipherText); | ||
lavaleri marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
@Test(expected = BadCiphertextException.class) | ||
public void incompleteCiphertext() { | ||
ParsedCiphertext pCt = new ParsedCiphertext(ciphertext_); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please update copyright.