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)
3838 cipher . send ( direction )
3939 cipher . key = cek
4040 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
4246 cipher . auth_data = auth_data
4347 end
4448
Original file line number Diff line number Diff line change 130130 end
131131 end
132132
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+
133141 context 'when the ciphertext is not valid' do
134142 it 'raises an error' do
135143 enc = klass . new ( key , group [ :iv ] )
You can’t perform that action at this time.
0 commit comments