lib/cose/key/ec2.rb in cose-0.1.0 vs lib/cose/key/ec2.rb in cose-0.2.0
- old
+ new
@@ -1,52 +1,48 @@
# frozen_string_literal: true
-require "cbor"
+require "cose/key/base"
module COSE
module Key
- class EC2
- KTY_LABEL = 1
+ class EC2 < Base
ALG_LABEL = 3
CRV_LABEL = -1
+ D_LABEL = -4
X_LABEL = -2
Y_LABEL = -3
KTY_EC2 = 2
- attr_reader :algorithm, :curve, :x_coordinate, :y_coordinate
+ attr_reader :algorithm, :curve, :d_coordinate, :x_coordinate, :y_coordinate
- def initialize(algorithm: nil, curve:, x_coordinate:, y_coordinate:)
+ def initialize(algorithm: nil, curve:, d_coordinate: nil, x_coordinate:, y_coordinate:)
if !curve
raise ArgumentError, "Required curve is missing"
elsif !x_coordinate
raise ArgumentError, "Required x-coordinate is missing"
elsif !y_coordinate
raise ArgumentError, "Required y-coordinate is missing"
else
@algorithm = algorithm
@curve = curve
+ @d_coordinate = d_coordinate
@x_coordinate = x_coordinate
@y_coordinate = y_coordinate
end
end
def self.from_map(map)
- if map[KTY_LABEL] == KTY_EC2
- new(
- algorithm: map[ALG_LABEL],
- curve: map[CRV_LABEL],
- x_coordinate: map[X_LABEL],
- y_coordinate: map[Y_LABEL]
- )
- else
- raise "Not an EC2 key"
- end
- end
+ enforce_type(map, KTY_EC2, "Not an EC2 key")
- def self.from_cbor(cbor)
- from_map(CBOR.decode(cbor))
+ new(
+ algorithm: map[ALG_LABEL],
+ curve: map[CRV_LABEL],
+ d_coordinate: map[D_LABEL],
+ x_coordinate: map[X_LABEL],
+ y_coordinate: map[Y_LABEL]
+ )
end
end
end
end