Sha256: c8c564e761de88aad4d7f249d36bf98b8395b1fb92698ca002add90445952f03

Contents?: true

Size: 778 Bytes

Versions: 7

Compression:

Stored size: 778 Bytes

Contents

# frozen_string_literal: true

require "cose/key/base"

module COSE
  module Key
    class Symmetric < Base
      LABEL_K = -1

      KTY_SYMMETRIC = 4

      attr_reader :k

      def self.enforce_type(map)
        if map[LABEL_KTY] != KTY_SYMMETRIC
          raise "Not a Symmetric key"
        end
      end

      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 map
        super.merge(LABEL_KTY => KTY_SYMMETRIC, LABEL_K => k)
      end

      def self.keyword_arguments_for_initialize(map)
        { k: map[LABEL_K] }
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
cose-0.11.0 lib/cose/key/symmetric.rb
cose-0.10.0 lib/cose/key/symmetric.rb
cose-0.9.0 lib/cose/key/symmetric.rb
cose-0.8.0 lib/cose/key/symmetric.rb
cose-0.7.0 lib/cose/key/symmetric.rb
cose-0.6.1 lib/cose/key/symmetric.rb
cose-0.6.0 lib/cose/key/symmetric.rb