|
44 | 44 | * =kid=: key id for identifying the key to use
|
45 | 45 | * =type=: type of the key, one of HMAC, RSA or ECDSA.
|
46 | 46 | * =algorithm=: algorithm to use, one of HS256, HS384, HS512, RS256, RS384, RS512, ES256, ES384 or ES512.
|
47 |
| - * =key=: private key to use - string for HMAC, private key file for RSA and private PEM file for ECDSA. |
| 47 | + * =key=: private key to use - string for HMAC, private key file for RSA and private PEM file for ECDSA. Optional for decoding, mandatory for encoding. |
48 | 48 | * =public_key=: public key to use - irrelevant for HMAC, public key file for RSA and public PEM file for ECDSA.
|
49 | 49 |
|
50 | 50 | RSA keys can be generated by:
|
|
268 | 268 | !.
|
269 | 269 | read_key_file(Key,KeyRead) :-
|
270 | 270 | member(Key.type, ['RSA', 'ECDSA']),
|
271 |
| - read_file_to_string(Key.key, KeyStr, []), |
| 271 | + get_dict('key', Key, PrivateKeyFile), |
| 272 | + !, |
| 273 | + read_file_to_string(PrivateKeyFile, KeyStr, []), |
272 | 274 | read_file_to_string(Key.public_key, PublicKeyStr, []),
|
273 | 275 | atom_string(KeyAtom, KeyStr),
|
274 | 276 | atom_string(PublicKeyAtom, PublicKeyStr),
|
275 | 277 | KeyRead = Key.put(_{key: KeyAtom, public_key: PublicKeyAtom}),
|
276 | 278 | !.
|
| 279 | +read_key_file(Key, KeyRead) :- |
| 280 | + member(Key.type, ['RSA', 'ECDSA']), |
| 281 | + read_file_to_string(Key.public_key, PublicKeyStr, []), |
| 282 | + atom_string(PublicKeyAtom, PublicKeyStr), |
| 283 | + KeyRead = Key.put(_{public_key: PublicKeyAtom}), |
| 284 | + !. |
| 285 | + |
277 | 286 |
|
278 | 287 | get_key_file(File, Key) :-
|
279 | 288 | read_file_to_string(File, KeyStr, []),
|
|
0 commit comments