Module: SBOM::CycloneDX::Record::Signature::JSFSignature::PublicKey

Defined in:
lib/sbom/cyclone_dx/record/signature.rb

Defined Under Namespace

Classes: EC, OKP, RSA

Constant Summary collapse

UNION_TYPE =

: [singleton(EC), singleton(OKP), singleton(RSA)]

[EC, OKP, RSA].freeze

Class Method Summary collapse

Class Method Details

.new(kty:, crv: nil, x: nil, y: nil, n: nil, e: nil) ⇒ Object

rubocop:disable Naming/MethodParameterName,Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/sbom/cyclone_dx/record/signature.rb', line 38

def self.new(kty:, crv: nil, x: nil, y: nil, n: nil, e: nil) # rubocop:disable Naming/MethodParameterName,Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity
  case kty
  when "EC"
    raise "`n` and `e` must be nil when kty == \"EC\"" unless n.nil? && e.nil?
    if crv.nil? || x.nil? || y.nil?
      raise ArgumentError, "`crv`, `x`, and `y` must not be nil when kty == \"EC\""
    end

    EC.new(crv: crv, x: x, y: y)
  when "OKP"
    raise "`y`, `n` and `e` must be nil when kty == \"OKP\"" unless y.nil? && n.nil? && e.nil?
    raise ArgumentError, "`crv` and `x` must not be nil when kty == \"OKP\"" if crv.nil? || x.nil?

    OKP.new(crv: crv, x: x)
  when "RSA"
    raise "`crv`, `x`, and `y` must be nil when kty == \"RSA\"" unless crv.nil? && x.nil? && y.nil?
    raise ArgumentError, "`n` and `e` must not be nil when kty == \"RSA\"" if n.nil? || e.nil?

    RSA.new(n: n, e: e)
  else
    raise ArgumentError, "Invalid value for `kty`"
  end
end