Skip to content
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

Remove the encoding system #65

Merged
merged 4 commits into from
Aug 12, 2013
Merged

Remove the encoding system #65

merged 4 commits into from
Aug 12, 2013

Conversation

tarcieri
Copy link
Contributor

@tarcieri tarcieri commented Aug 8, 2013

After much discussion it was agreed that the encoding system was out of place in
this library.

This commit removes it, and hopefully improves the general quality of the
codebase as well. All encoding-related thunks and glue code have been removed,
the way TestVectors work have been standardized, and any stray test vectors
still lingering inside of the tests have been moved to test_vectors.rb

Fixes #54

After much discussion it was agreed that the encoding system was out of place in
this library.

This commit removes it, and hopefully improves the general quality of the
codebase as well. All encoding-related thunks and glue code have been removed,
the way TestVectors work have been standardized, and any stray test vectors
still lingering inside of the tests have been moved to test_vectors.rb

Fixes #54
@tarcieri
Copy link
Contributor Author

tarcieri commented Aug 8, 2013

feels good man

@@ -20,7 +17,8 @@
end

it "raises on a nil public key" do
expect { Crypto::Box.new(nil, bobsk) }.to raise_error(Crypto::LengthError, /Public key was 0 bytes \(Expected 32\)/)
expect { Crypto::Box.new(nil, bobsk) }.to raise_error(NoMethodError)
pending "is a failed #to_s (NoMethodError) here sufficient?"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@namelessjon what do you feel about this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should definitely wrap such an error in something more descriptive than a nil complaining.

@coveralls
Copy link

Coverage Status

Coverage increased (+0%) when pulling 9b08bc7 on nuke-encoding-system into f325a36 on master.

@namelessjon
Copy link
Contributor

Looks good. Much simpler interfaces on everything 😀

I think we should keep a Util.bin2hex and Util.hex2bin method pair around. It's two oneliners, but they're useful for inspecting output on debugging and things like that. It's no extra dependencies, and doesn't clutter the main API.

# @param encoding [String] string encoding format in which to encode the key
#
# @return [String] key encoded in the specified format
def to_s(encoding = :raw)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing this is going to break #inspect, which relies on #to_s(:hex) being valid, so you should change that line too. Perhaps to use the Util.bin2hex method I suggested. Also, to avoid the chance of leaking 8 bytes of actual key, we could do something like compute the 8 byte Blake2b digest of the whole key and show that?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch.

This replaces previous NoMethodError #to_s exceptions with a TypeError informing
users that the given class can't be coerced to a String with #to_str
@coveralls
Copy link

Coverage Status

Coverage increased (+0%) when pulling 0aa5db8 on nuke-encoding-system into f325a36 on master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0%) when pulling 0aa5db8 on nuke-encoding-system into 269baed on master.

@tarcieri
Copy link
Contributor Author

@namelessjon I think that should cover all the remaining problems, except perhaps first hashing serializables before inspecting them

@coveralls
Copy link

Coverage Status

Coverage increased (+0%) when pulling 8f41d94 on nuke-encoding-system into 269baed on master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0%) when pulling 8f41d94 on nuke-encoding-system into 269baed on master.

@tarcieri
Copy link
Contributor Author

@namelessjon does this look good to you? I'd suggest tabling the #inspect-showing-partial-key vs a hash as a separate issue

namelessjon added a commit that referenced this pull request Aug 12, 2013
Remove the encoding system

This makes things one hell of a lot simpler to work with.  We do keep bin2hex/hex2bin though.  We're not monsters.
@namelessjon namelessjon merged commit 11ef589 into master Aug 12, 2013
@namelessjon namelessjon deleted the nuke-encoding-system branch August 12, 2013 07:40
@tarcieri
Copy link
Contributor Author

I'll take that as a yes ;)

@namelessjon
Copy link
Contributor

Seemed like the shortest way to say it 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove the encoding system!
4 participants