Skip to content

Commit

Permalink
Remove unnecessary size checks from XChaCha20
Browse files Browse the repository at this point in the history
libsodium handles the case of both a long and short key gracefully
  • Loading branch information
bannable committed Nov 29, 2022
1 parent 0eda19f commit 5e58340
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 15 deletions.
8 changes: 1 addition & 7 deletions lib/paseto/sodium/stream/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,9 @@ def self.key_bytes
# Create a new Stream.
#
# Sets up Stream with a secret key for encrypting and decrypting messages.
#
# @param key [String] The key to encrypt and decrypt with
#
# @raise [RbNaCl::LengthError] on invalid keys
#
# @return [RbNaCL::Stream::Base] The new Stream construct, ready to use
sig { params(key: String).void }
def initialize(key)
@key = T.let(RbNaCl::Util.check_string(key, key_bytes, 'Secret key'), String)
@key = key
end

sig { params(nonce: String, message: T.nilable(String)).returns(String) }
Expand Down
8 changes: 0 additions & 8 deletions spec/paseto/sodium/stream/x_cha_cha20_xor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,6 @@
it 'raises on a nil key' do
expect { described_class.new(nil) }.to raise_error(TypeError)
end

it 'raises on a short key' do
expect { described_class.new('hello') }.to raise_error RbNaCl::LengthError
end

it 'raises on a long key' do
expect { described_class.new("hello#{key}") }.to raise_error RbNaCl::LengthError
end
end

describe '#encrypt' do
Expand Down

0 comments on commit 5e58340

Please sign in to comment.