Module: ECDSA::Format::PointOctetString

Defined in:
lib/tapyrus/ext/ecdsa.rb

Class Method Summary collapse

Class Method Details

.decode(string, group, allow_hybrid: false) ⇒ Object

Raises:

  • (ECDSA::Format::DecodeError)


15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# 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