Skip to content
This repository was archived by the owner on Feb 5, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/miscreant/aes/siv.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def seal(plaintext, associated_data = [])
# @raise [Miscreant::IntegrityError] ciphertext and/or associated data are corrupt or tampered with
# @return [String] decrypted plaintext
def open(ciphertext, associated_data = [])
raise TypeError, "expected String, got #{ciphertext.class}" unless ciphertext.is_a?(String)
Internals::Util.validate_bytestring("ciphertext", ciphertext)

v = ciphertext[0, Internals::Block::SIZE]
plaintext = @ctr.encrypt(_zero_iv_bits(v), ciphertext[Internals::Block::SIZE..-1])
Expand Down
9 changes: 9 additions & 0 deletions spec/miscreant/aead_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@
end.to raise_error(Miscreant::IntegrityError)
end
end

it "should raise ArgumentError if wrong encoding" do
ex = test_vectors.first
aead = described_class.new(ex.alg, ex.key)
ciphertext = ex.ciphertext.dup.force_encoding(Encoding::UTF_8)
expect do
aead.open(ciphertext, nonce: example_nonce, ad: example_ad)
end.to raise_error(ArgumentError, "ciphertext must be Encoding::BINARY")
end
end
end
end