crypto: simplify api/forms key validation
This commit is contained in:
parent
7ff7398aff
commit
ffee86fcf3
|
@ -22,8 +22,7 @@ class CertificateKeyPairSerializer(ModelSerializer):
|
|||
def validate_key_data(self, value):
|
||||
"""Verify that input is a valid PEM RSA Key"""
|
||||
# Since this field is optional, data can be empty.
|
||||
if value == "":
|
||||
return value
|
||||
if value != "":
|
||||
try:
|
||||
load_pem_private_key(
|
||||
str.encode("\n".join([x.strip() for x in value.split("\n")])),
|
||||
|
|
|
@ -26,8 +26,7 @@ class CertificateKeyPairForm(forms.ModelForm):
|
|||
"""Verify that input is a valid PEM RSA Key"""
|
||||
key_data = self.cleaned_data["key_data"]
|
||||
# Since this field is optional, data can be empty.
|
||||
if key_data == "":
|
||||
return key_data
|
||||
if key_data != "":
|
||||
try:
|
||||
load_pem_private_key(
|
||||
str.encode("\n".join([x.strip() for x in key_data.split("\n")])),
|
||||
|
|
Reference in New Issue