-
Notifications
You must be signed in to change notification settings - Fork 123
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
Adding a validate version error handling as discussed in issue #113 #116
Conversation
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.
Thanks for taking a look! A couple of comments so far.
aws-encryption-sdk-java.iml
Outdated
@@ -0,0 +1,215 @@ | |||
<?xml version="1.0" encoding="UTF-8"?> |
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.
We probably don't want to commit this?
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.
Not sure where this file came from, but if this is an IDE/build artifact, let's also add it to the .gitignore
.
@@ -179,6 +179,9 @@ public Boolean isComplete() { | |||
*/ | |||
private int parseVersion(final byte[] b, final int off) throws ParseException { | |||
version_ = PrimitivesParser.parseByte(b, off); | |||
if(CiphertextType.deserialize(version_) == null) { |
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 add some tests
@@ -179,6 +179,9 @@ public Boolean isComplete() { | |||
*/ | |||
private int parseVersion(final byte[] b, final int off) throws ParseException { | |||
version_ = PrimitivesParser.parseByte(b, off); | |||
if(CiphertextType.deserialize(version_) == null) { |
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.
This is not the correct check.
We currently only have one valid version: (hex) 01
. Any other value MUST throw an error.
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.
Also, we need tests that actually trigger this failure mode.
.gitignore
Outdated
@@ -5,3 +5,4 @@ target/ | |||
.classpath | |||
/bin/ | |||
.idea/ | |||
*.iml/ |
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.
This is good, but aws-encryption-sdk-java.iml
is still in the diff.
@@ -179,6 +180,9 @@ public Boolean isComplete() { | |||
*/ | |||
private int parseVersion(final byte[] b, final int off) throws ParseException { | |||
version_ = PrimitivesParser.parseByte(b, off); | |||
if(CiphertextType.deserialize(version_).getValue() != Byte.parseByte(VersionInfo.VERSION_NUM, 16)) { |
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.
This is the major version of this implementation, not the ciphertext message format version. You want CURRENT_CIPHERTEXT_VERSION
.
if(CiphertextType.deserialize(version_).getValue() != Byte.parseByte(VersionInfo.VERSION_NUM, 16)) { | |
if(CiphertextType.deserialize(version_).getValue() != Byte.parseByte(VersionInfo.CURRENT_CIPHERTEXT_VERSION, 16)) { |
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 actually change as follows: (note lack of parsing and space after if
if (CiphertextType.deserialize(version_).getValue() != VersionInfo.CURRENT_CIPHERTEXT_VERSION) {
*.iml is in the .gitignore
…ipherText_Version. Added .iml to the gitignore
@@ -179,6 +180,9 @@ public Boolean isComplete() { | |||
*/ | |||
private int parseVersion(final byte[] b, final int off) throws ParseException { | |||
version_ = PrimitivesParser.parseByte(b, off); | |||
if(CiphertextType.deserialize(version_).getValue() != Byte.parseByte(VersionInfo.VERSION_NUM, 16)) { |
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 actually change as follows: (note lack of parsing and space after if
if (CiphertextType.deserialize(version_).getValue() != VersionInfo.CURRENT_CIPHERTEXT_VERSION) {
@@ -179,6 +180,9 @@ public Boolean isComplete() { | |||
*/ | |||
private int parseVersion(final byte[] b, final int off) throws ParseException { | |||
version_ = PrimitivesParser.parseByte(b, off); | |||
if(CiphertextType.deserialize(version_).getValue() != VersionInfo.CURRENT_CIPHERTEXT_VERSION ) { |
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.
Our style requires a space between the if
and before the (
.
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.
LGTM
…e version to a ciphertext type and deserialzing it when all it needed to do was compare the bytes.
…sed to parseVersion it would never throw the error because the value was the same as CURRENT_CIPHERTEXT_VERSION. The test would pass but the error would not be thrown. It is now fixed and it throws the right error when it receives a wrong version.
…e the byte that didn't contain the version type. However, test still passed because the previous version of the test would offset to where the byte was changed. That has been fixed and the test now overrides the byte that holds the version number.
Requested test has been added and requested constant has been used. Matt is on vacation.
Issue #, if available:
Description of changes:
Issue #113
Added the version error handling.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.