Skip to content

Commit

Permalink
WIP - ensure the EC curve parameters aren't dropped on PKCS-8 convers…
Browse files Browse the repository at this point in the history
…ion (see issue #82)
  • Loading branch information
potatosalad committed Jan 8, 2020
1 parent ae03cdb commit 571a7be
Showing 1 changed file with 24 additions and 9 deletions.
33 changes: 24 additions & 9 deletions src/jose_public_key.erl
Original file line number Diff line number Diff line change
Expand Up @@ -747,15 +747,6 @@ encode_handle_open_type_wrapper(Type) ->
{asn1_OPENTYPE, Type}.

%% @private
i2k(#'SubjectPublicKeyInfo'{
algorithm =
#'AlgorithmIdentifier'{
algorithm = ?'id-ecPublicKey',
parameters = ECParameters
},
subjectPublicKey = ECPublicKey
}) ->
{#'ECPoint'{point = ECPublicKey}, der_decode('EcpkParameters', ECParameters)};
i2k(#'PrivateKeyInfo'{
privateKeyAlgorithm =
#'PrivateKeyInfo_privateKeyAlgorithm'{
Expand Down Expand Up @@ -840,6 +831,30 @@ i2k(#'SubjectPublicKeyInfo'{
subjectPublicKey = << PublicKey:56/binary >>
}) ->
#'jose_X448PublicKey'{ publicKey = PublicKey };
% public_key compat
i2k(#'SubjectPublicKeyInfo'{
algorithm =
#'AlgorithmIdentifier'{
algorithm = ?'id-ecPublicKey',
parameters = ECParameters
},
subjectPublicKey = ECPublicKey
}) ->
{#'ECPoint'{point = ECPublicKey}, der_decode('EcpkParameters', ECParameters)};
i2k(PrivateKeyInfo=#'PrivateKeyInfo'{
privateKeyAlgorithm =
#'PrivateKeyInfo_privateKeyAlgorithm'{
algorithm = ?'id-ecPublicKey',
parameters = {asn1_OPENTYPE, EcpkParameters}
},
privateKey = PrivateKey
}) ->
case der_decode('ECPrivateKey', PrivateKey) of
ECPrivateKey = #'ECPrivateKey'{parameters = asn1_NOVALUE} ->
ECPrivateKey#'ECPrivateKey'{parameters = der_decode('EcpkParameters', EcpkParameters)};
_ ->
PrivateKeyInfo
end;
i2k(Info) ->
Info.

Expand Down

0 comments on commit 571a7be

Please sign in to comment.