Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Remove Ciphertext

It's breaking the 1.0 API.  That's the price of rushing for 1.0, I
guess.
  • Loading branch information...
commit 3652ca3ddc07c6d9428e462d11ca8c0520a1dc0e 1 parent 658be94
@namelessjon namelessjon authored
View
1  lib/rbnacl.rb
@@ -25,7 +25,6 @@ class LengthError < ArgumentError; end
require "rbnacl/keys/public_key"
require "rbnacl/keys/signing_key"
require "rbnacl/keys/verify_key"
-require "rbnacl/ciphertext"
require "rbnacl/box"
require "rbnacl/secret_box"
require "rbnacl/hash"
View
5 lib/rbnacl/box/curve25519_xsalsa20_poly1305.rb
@@ -38,7 +38,7 @@ class Box
class Curve25519XSalsa20Poly1305
# Number of bytes for a nonce
NONCEBYTES = NaCl::CURVE25519_XSALSA20_POLY1305_BOX_NONCEBYTES
-
+
# Number of bytes for the shared key
BEFORENMBYTES = NaCl::CURVE25519_XSALSA20_POLY1305_BOX_BEFORENMBYTES
@@ -101,8 +101,7 @@ def box(nonce, message)
ct = Util.zeros(msg.bytesize)
NaCl.crypto_box_curve25519_xsalsa20_poly1305_afternm(ct, msg, msg.bytesize, nonce, beforenm) || raise(CryptoError, "Encryption failed")
- ct = Util.remove_zeros(NaCl::BOXZEROBYTES, ct)
- Ciphertext.new(ct, primitive)
+ Util.remove_zeros(NaCl::BOXZEROBYTES, ct)
end
alias encrypt box
View
57 lib/rbnacl/ciphertext.rb
@@ -1,57 +0,0 @@
-# encoding: binary
-module Crypto
- # A Ciphertext returned by the library
- #
- # Holds the ciphertext returned by the library. This acts like a string in
- # many cases, but also supports interrogating for the primitive used and can
- # be encoded into a variety of formats.
- class Ciphertext
- attr_reader :ciphertext, :primitive
- attr_accessor :default_encoding
- def initialize(ciphertext, primitive, default_encoding = :raw)
- @ciphertext = ciphertext
- @primitive = primitive
- @default_encoding = default_encoding
- end
-
- # Returns the ciphertext string
- #
- # Optionally encodes it too
- #
- # @param encoding [Symbol] encoding to use
- #
- # @return [String] ciphertext
- def to_str(encoding = default_encoding)
- Encoder[encoding].encode(ciphertext)
- end
-
- alias to_s to_str
-
-
- def inspect
- "#<#{self.class}:#{primitive}:#{to_str(:hex)[0,16]}>"
- end
-
- # size of the ciphertext in bytes
- #
- # This returns the size in the specified encoding, to avoid confusion
- # in the case of a non-raw default encoding.
- #
- # @param encoding [Symbol] encoding to use
- #
- # @return [Integer bytesize of encoded ciphertext
- def bytesize(encoding = default_encoding)
- to_s(encoding).bytesize
- end
-
- # Concatenate a string
- def +(thing)
- to_s + thing.to_s
- end
-
- # tests for equality by converting a to string
- def ==(thing)
- thing.respond_to?(:to_s) ? to_s == thing.to_s : false
- end
- end
-end
View
3  lib/rbnacl/secret_box/xsalsa20_poly1305.rb
@@ -89,8 +89,7 @@ def box(nonce, message)
ct = Util.zeros(msg.bytesize)
NaCl.crypto_secretbox_xsalsa20poly1305(ct, msg, msg.bytesize, nonce, @key) || raise(CryptoError, "Encryption failed")
- ct = Util.remove_zeros(NaCl::BOXZEROBYTES, ct)
- Ciphertext.new(ct, primitive)
+ Util.remove_zeros(NaCl::BOXZEROBYTES, ct)
end
alias encrypt box
Please sign in to comment.
Something went wrong with that request. Please try again.