File tree Expand file tree Collapse file tree 2 files changed +13
-1
lines changed Expand file tree Collapse file tree 2 files changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -38,7 +38,11 @@ def setup_cipher(direction, auth_data)
38
38
cipher . send ( direction )
39
39
cipher . key = cek
40
40
cipher . iv = iv
41
- cipher . auth_tag = tag if direction == :decrypt
41
+ if direction == :decrypt
42
+ raise JWE ::InvalidData , 'Invalid ciphertext or authentication tag' unless tag . bytesize == 16
43
+
44
+ cipher . auth_tag = tag
45
+ end
42
46
cipher . auth_data = auth_data
43
47
end
44
48
Original file line number Diff line number Diff line change 130
130
end
131
131
end
132
132
133
+ context 'when the tag is not 16 bytes' do
134
+ it 'raises an error' do
135
+ enc = klass . new ( key , group [ :iv ] )
136
+ enc . tag = group [ :tag ] [ 0 ...-1 ]
137
+ expect { enc . decrypt ( group [ :helloworld ] , '' ) } . to raise_error ( JWE ::InvalidData )
138
+ end
139
+ end
140
+
133
141
context 'when the ciphertext is not valid' do
134
142
it 'raises an error' do
135
143
enc = klass . new ( key , group [ :iv ] )
You can’t perform that action at this time.
0 commit comments