module ECDSA::Format::PointOctetString
Public Class Methods
decode(string, group, allow_hybrid: false)
click to toggle source
# File lib/tapyrus/ext/ecdsa.rb, line 15 def self.decode(string, group, allow_hybrid: false) string = string.dup.force_encoding('BINARY') raise ECDSA::Format::DecodeError, 'Point octet string is empty.' if string.empty? case string[0].ord when 0 check_length string, 1 return group.infinity when 2 decode_compressed string, group, 0 when 3 decode_compressed string, group, 1 when 4 decode_uncompressed string, group when 6..7 unless allow_hybrid raise ECDSA::Format::DecodeError, 'Unrecognized start byte for point octet string: 0x%x' % string[0].ord end decode_uncompressed string, group if allow_hybrid else raise ECDSA::Format::DecodeError, 'Unrecognized start byte for point octet string: 0x%x' % string[0].ord end end