@@ -37,6 +37,10 @@ def make_enum_type(enum_cls: EnumMeta) -> click.Choice:
37
37
return click .Choice ([variant .value for variant in enum_cls ], case_sensitive = False )
38
38
39
39
40
+ def base64_input (s : str ) -> Base64 :
41
+ return Base64 .from_encoded (s , ignore_whitespace = True )
42
+
43
+
40
44
API_CERTIFICATE_MIME_TYPE = "application/x-pem-file"
41
45
KEY_CERTIFICATE_MIME_TYPES = [
42
46
"application/x-pem-file" ,
@@ -688,9 +692,9 @@ def add_key(
688
692
if not public_exponent :
689
693
public_exponent = prompt_str ("Public exponent" )
690
694
private_key = nethsm_sdk .RsaPrivateKey (
691
- prime_p = Base64 . from_encoded (prime_p ),
692
- prime_q = Base64 . from_encoded (prime_q ),
693
- public_exponent = Base64 . from_encoded (public_exponent ),
695
+ prime_p = base64_input (prime_p ),
696
+ prime_q = base64_input (prime_q ),
697
+ public_exponent = base64_input (public_exponent ),
694
698
)
695
699
else :
696
700
if prime_p :
@@ -703,7 +707,7 @@ def add_key(
703
707
)
704
708
if not data :
705
709
data = prompt_str ("Key data" )
706
- private_key = nethsm_sdk .GenericPrivateKey (data = Base64 . from_encoded (data ))
710
+ private_key = nethsm_sdk .GenericPrivateKey (data = base64_input (data ))
707
711
708
712
with connect (ctx ) as nethsm :
709
713
key_id = nethsm .add_key (
@@ -1543,9 +1547,9 @@ def encrypt(ctx: Context, key_id: str, data: str, mode: str, iv: Optional[str])
1543
1547
with connect (ctx ) as nethsm :
1544
1548
encrypted = nethsm .encrypt (
1545
1549
key_id ,
1546
- Base64 . from_encoded (data ),
1550
+ base64_input (data ),
1547
1551
nethsm_sdk .EncryptMode .from_string (mode ),
1548
- iv = Base64 . from_encoded (iv ) if iv else None ,
1552
+ iv = base64_input (iv ) if iv else None ,
1549
1553
)
1550
1554
print (f"Encrypted: { encrypted .encrypted .data } " )
1551
1555
print (f"Initialization vector: { encrypted .iv .data } " )
@@ -1586,9 +1590,9 @@ def decrypt(ctx: Context, key_id: str, data: str, mode: str, iv: Optional[str])
1586
1590
with connect (ctx ) as nethsm :
1587
1591
decrypted = nethsm .decrypt (
1588
1592
key_id ,
1589
- Base64 . from_encoded (data ),
1593
+ base64_input (data ),
1590
1594
nethsm_sdk .DecryptMode .from_string (mode ),
1591
- Base64 . from_encoded (iv ) if iv else None ,
1595
+ base64_input (iv ) if iv else None ,
1592
1596
)
1593
1597
print (decrypted .data )
1594
1598
@@ -1620,6 +1624,6 @@ def sign(ctx: Context, key_id: str, data: str, mode: str) -> None:
1620
1624
This command requires authentication as a user with the Operator role."""
1621
1625
with connect (ctx ) as nethsm :
1622
1626
signature = nethsm .sign (
1623
- key_id , Base64 . from_encoded (data ), nethsm_sdk .SignMode .from_string (mode )
1627
+ key_id , base64_input (data ), nethsm_sdk .SignMode .from_string (mode )
1624
1628
)
1625
1629
print (signature .data )
0 commit comments