Sha256: 60dc8ffd34108ff7f1f3b2246d442834604f8af887115b53f732225b76f043e4

Contents?: true

Size: 767 Bytes

Versions: 6

Compression:

Stored size: 767 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/MethodParameterName
        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

6 entries across 6 versions & 1 rubygems

Version Path
cose-1.3.1 lib/cose/key/symmetric.rb
cose-1.3.0 lib/cose/key/symmetric.rb
cose-1.2.1 lib/cose/key/symmetric.rb
cose-1.2.0 lib/cose/key/symmetric.rb
cose-1.1.0 lib/cose/key/symmetric.rb
cose-1.0.0 lib/cose/key/symmetric.rb