Module: CLValueBytesParsers::CLPublicKeyBytesParser
- Extended by:
- CLPublicKeyBytesParser
- Included in:
- CLPublicKey, CLPublicKeyBytesParser
- Defined in:
- lib/serialization/cl_value_bytes_parsers.rb
Instance Method Summary collapse
-
#decode_base_16(str) ⇒ Array<Integer>
Decoded.
-
#encode_base_16(byte_array) ⇒ String
Encoded.
- #from_bytes(byte_array) ⇒ Object
- #to_bytes(cl_public_key) ⇒ Object
Instance Method Details
#decode_base_16(str) ⇒ Array<Integer>
Returns decoded.
384 385 386 |
# File 'lib/serialization/cl_value_bytes_parsers.rb', line 384 def decode_base_16(str) decoded = [str].pack('H*').unpack("C*") end |
#encode_base_16(byte_array) ⇒ String
Returns encoded.
390 391 392 |
# File 'lib/serialization/cl_value_bytes_parsers.rb', line 390 def encode_base_16(byte_array) encoded = byte_array.pack("C*").unpack("H*").first end |
#from_bytes(byte_array) ⇒ Object
400 401 402 403 404 405 406 407 408 409 410 411 412 |
# File 'lib/serialization/cl_value_bytes_parsers.rb', line 400 def from_bytes(byte_array) byte_array # tag = byte_array[0] tag = 0 if byte_array[0] == 1 && byte_array.size == 33 tag = 1 elsif byte_array[0] == 2 && byte_array.size == 34 tag = 2 else raise ArgumentError.new("Invalid parameter") end CLPublicKey.new(byte_array[1..], tag) end |
#to_bytes(cl_public_key) ⇒ Object
394 395 396 397 398 |
# File 'lib/serialization/cl_value_bytes_parsers.rb', line 394 def to_bytes(cl_public_key) tag = cl_public_key.get_cl_public_key_tag raw_public_key = cl_public_key.get_value [tag] + raw_public_key end |