Skip to content

Commit

Permalink
Merge pull request #56 from bdewater/compact-hash
Browse files Browse the repository at this point in the history
Use Hash#compact instead of rejecting nil values
  • Loading branch information
grzuy committed May 18, 2020
2 parents 53813fc + 5cd153d commit 7bb7158
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 16 deletions.
6 changes: 2 additions & 4 deletions lib/cose/key/base.rb
Expand Up @@ -41,14 +41,12 @@ def serialize
end

def map
map = {
{
LABEL_BASE_IV => base_iv,
LABEL_KEY_OPS => key_ops,
LABEL_ALG => alg,
LABEL_KID => kid,
}

map.reject { |_k, v| v.nil? }
}.compact
end
end
end
Expand Down
6 changes: 2 additions & 4 deletions lib/cose/key/curve_key.rb
Expand Up @@ -35,13 +35,11 @@ def initialize(crv:, x: nil, d: nil, **keyword_arguments) # rubocop:disable Nami
end

def map
map = super.merge(
super.merge(
LABEL_CRV => crv,
LABEL_X => x,
LABEL_D => d
)

map.reject { |_k, v| v.nil? }
).compact
end
end
end
Expand Down
6 changes: 2 additions & 4 deletions lib/cose/key/ec2.rb
Expand Up @@ -59,12 +59,10 @@ def initialize(y: nil, **keyword_arguments) # rubocop:disable Naming/MethodParam
end

def map
map = super.merge(
super.merge(
Base::LABEL_KTY => KTY_EC2,
LABEL_Y => y,
)

map.reject { |_k, v| v.nil? }
).compact
end

def to_pkey
Expand Down
6 changes: 2 additions & 4 deletions lib/cose/key/rsa.rb
Expand Up @@ -74,7 +74,7 @@ def initialize(n:, e:, d: nil, p: nil, q: nil, dp: nil, dq: nil, qinv: nil, **ke
end

def map
map = super.merge(
super.merge(
Base::LABEL_KTY => KTY_RSA,
LABEL_N => n,
LABEL_E => e,
Expand All @@ -84,9 +84,7 @@ def map
LABEL_DP => dp,
LABEL_DQ => dq,
LABEL_QINV => qinv
)

map.reject { |_k, v| v.nil? }
).compact
end

def to_pkey
Expand Down

0 comments on commit 7bb7158

Please sign in to comment.