Module: PathgraphEncoding::PublicKey

Defined in:
lib/pathgraph_encoding.rb

Overview

Represents a pathgraph public key.

Class Method Summary collapse

Class Method Details

.from_der(der) ⇒ Object

Decode and build a instance of a pathgraph public key from a DER-formatted bytes array.

Parameters:

der

A byte array representing the public key specified.

Returns:

key

The public key dencoded.



189
190
191
# File 'lib/pathgraph_encoding.rb', line 189

def self.from_der(der)
  # TODO: implement this method
end

.is_valid?(key) ⇒ Boolean

Check if is a valid public key.

Parameters:

key

A byte array representing the public key specified.

Returns:

Returns ‘true` if is a valid public key, otherwise `false`.

Returns:

  • (Boolean)


203
204
205
# File 'lib/pathgraph_encoding.rb', line 203

def self.is_valid?(key)
  # TODO: implement this method
end

.to_der(key) ⇒ Object

Compute DER-formatted bytes array of a pathgraph public key.

Parameters:

key

A public key to encode.

Returns:

A byte array representing the public key specified.



160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# File 'lib/pathgraph_encoding.rb', line 160

def self.to_der(key)
  n = OpenSSL::ASN1::Integer.new(key[:n])
  # m = OpenSSL::ASN1::Integer.new(key[:m])
  # k = OpenSSL::ASN1::Integer.new(key[:k])
  sigma = OpenSSL::ASN1::Sequence.new(
    key[:sigma].map do |sig|
      arr = sig.map { |x| OpenSSL::ASN1::Integer.new(x) }
      OpenSSL::ASN1::Sequence.new(arr)
    end
  )
  publicKey = OpenSSL::ASN1::Sequence.new([n,sigma])

  version = OpenSSL::ASN1::PrintableString.new("0.0.1")
  instance = OpenSSL::ASN1::Sequence.new([version,publicKey])

  instance.to_der
end