Skip to content

Commit 3cf221d

Browse files
committed
simplify
1 parent 4c97264 commit 3cf221d

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

src/cryptojwt/tools/keyconv.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,6 @@ def pem2ec(filename: str, kid: str = None, private: bool = False, passphrase: st
4545
return jwk
4646

4747

48-
def jwk2bin(jwk: JWK) -> bytes:
49-
"""Convert symmetric key from JWK to binary"""
50-
return jwk.key
51-
52-
5348
def pem2jwk(filename: str, kid: str, private: bool = False) -> bytes:
5449

5550
with open(filename, 'rt') as file:
@@ -80,6 +75,9 @@ def pem2jwk(filename: str, kid: str, private: bool = False) -> bytes:
8075
def jwk2pem(jwk: JWK, private: bool = False) -> bytes:
8176
"""Convert asymmetric key from JWK to PEM"""
8277

78+
if jwk.kty == 'oct':
79+
return jwk.key
80+
8381
if private:
8482
passphrase = getpass('Private key passphrase: ')
8583
if passphrase:
@@ -121,10 +119,7 @@ def main():
121119

122120
if f.endswith('.json'):
123121
jwk = jwk_from_file(f, args.private)
124-
if jwk.kty == 'oct':
125-
serialized = jwk2bin(jwk)
126-
else:
127-
serialized = jwk2pem(jwk, args.private)
122+
serialized = jwk2pem(jwk, args.private)
128123

129124
if args.output:
130125
with open(args.output, mode='wt') as file:

0 commit comments

Comments
 (0)