Skip to content

Commit

Permalink
Merge pull request #139 from spencerdcarlson/main
Browse files Browse the repository at this point in the history
Hide kty in %JOSE.JWK{} when it is inspected
  • Loading branch information
potatosalad authored Dec 15, 2022
2 parents 8b8c52a + 27c8d13 commit 4af5a4a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/jose/jwk.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ defmodule JOSE.JWK do
vals = :lists.map(&{&1, [], nil}, keys)
pairs = :lists.zip(keys, vals)

@derive {Inspect, except: [:kty]}
defstruct keys
@type t :: %__MODULE__{}

Expand Down Expand Up @@ -782,7 +783,7 @@ defmodule JOSE.JWK do
:jose_jwk.box_encrypt_ecdh_es(plain_text, jwe, v_static_public_key, u_ephemeral_secret_key)
end

@doc """
@doc """
ECDH-SS Key Agreement decryption of the `encrypted` binary or map using `v_static_secret_key`. See `box_encrypt_ecdh_ss/2` and `JOSE.JWE.block_decrypt/2`.
"""
def box_decrypt_ecdh_ss(encrypted, v_static_secret_key) do
Expand Down
15 changes: 15 additions & 0 deletions test/jose_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,21 @@ defmodule JOSETest do
assert jwk == JOSE.JWK.from_pem(password, JOSE.JWK.to_pem(password, jwk))
end

test "JOSE.JWK display" do
map = %{
"crv" => "P-256",
"d" => "aJhYDBNS-5yrH97PAExzWNLlJGqJwFGZmv7iJvdG4p0",
"kty" => "EC",
"x" => "LksdLpZN3ijcn_TBfRK-_tgmvws0c5_V5k0bg14RLhU",
"y" => "ukc-JOEAWhW664SY5Q29xHlAVEDlrQwYF3-vQ_cdi1s"
}

jwk = JOSE.JWK.from_map(map)
stdout = inspect(jwk)
assert match?("#JOSE.JWK<" <> _, stdout)
refute String.contains?(stdout, "kty")
end

test "JOSE.JWS decode and encode" do
map = %{"alg" => "HS256"}
binary = JOSE.encode(map)
Expand Down

0 comments on commit 4af5a4a

Please sign in to comment.