lib/cose/key/symmetric.rb in cose-0.5.0 vs lib/cose/key/symmetric.rb in cose-0.6.0
- old
+ new
@@ -3,26 +3,37 @@
require "cose/key/base"
module COSE
module Key
class Symmetric < Base
- K_LABEL = -1
+ LABEL_K = -1
+
KTY_SYMMETRIC = 4
- attr_reader :key_value
+ attr_reader :k
- def initialize(key_value:)
- if !key_value
- raise ArgumentError, "Required key value is missing"
+ def self.enforce_type(map)
+ if map[LABEL_KTY] != KTY_SYMMETRIC
+ raise "Not a Symmetric key"
end
+ end
- @key_value = key_value
+ def initialize(k:, **keyword_arguments) # rubocop:disable Naming/UncommunicativeMethodParamName
+ super(**keyword_arguments)
+
+ if !k
+ raise ArgumentError, "Required key value k is missing"
+ else
+ @k = k
+ end
end
- def self.from_map(map)
- enforce_type(map, KTY_SYMMETRIC, "Not a Symmetric key")
+ def map
+ super.merge(LABEL_KTY => KTY_SYMMETRIC, LABEL_K => k)
+ end
- new(key_value: map[K_LABEL])
+ def self.keyword_arguments_for_initialize(map)
+ { k: map[LABEL_K] }
end
end
end
end