Method: ECDSA::Format::PointOctetString.encode

Defined in:
lib/ecdsa/format/point_octet_string.rb

.encode(point, opts = {}) ⇒ Object

Converts a Point to an octet string.

Parameters:

  • point (Point)
  • opts (Hash) (defaults to: {})

Options Hash (opts):

  • :compression (Object)

    Set this option to true to generate a compressed octet string, which only has one bit of the Y coordinate. (Default: false)



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/ecdsa/format/point_octet_string.rb', line 21

def self.encode(point, opts = {})
  return "\x00" if point.infinity?

  if opts[:compression]
    start_byte = point.y.even? ? "\x02" : "\x03"
    start_byte + FieldElementOctetString.encode(point.x, point.group.field)
  else
    "\x04" +
      FieldElementOctetString.encode(point.x, point.group.field) +
      FieldElementOctetString.encode(point.y, point.group.field)
  end
end