Module: JOSE::JWA::PKCS7
Instance Method Summary collapse
Instance Method Details
#pad(binary) ⇒ Object
5 6 7 8 |
# File 'lib/jose/jwa/pkcs7.rb', line 5 def pad(binary) size = 16 - (binary.bytesize % 16) return [binary, *([size] * size)].pack('a*C*') end |
#unpad(binary) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/jose/jwa/pkcs7.rb', line 10 def unpad(binary) p = binary.getbyte(-1) size = binary.bytesize - p binary_s = StringIO.new(binary) result = binary_s.read(size) p.times do if binary_s.getbyte != p raise ArgumentError, "unrecognized padding" end end return result end |