mirror of
https://github.com/r4sas/py-i2phosts
synced 2025-01-22 04:24:15 +00:00
validation.py: add support for ECDSA keys
This commit is contained in:
parent
1fbcdeb4bd
commit
38a792c7c0
@ -85,7 +85,7 @@ def validate_b64hash(data, check_uniq=True):
|
|||||||
if length > 616:
|
if length > 616:
|
||||||
raise ValidationError(_('Specified base64 hash is bigger than 616 bytes'))
|
raise ValidationError(_('Specified base64 hash is bigger than 616 bytes'))
|
||||||
# keys with cert may ends with anything, so check is relaxed
|
# keys with cert may ends with anything, so check is relaxed
|
||||||
if length > 516 and re.match(r'[a-zA-Z0-9\-~]+$', data) == None:
|
if length > 516 and re.match(r'[a-zA-Z0-9\-~=]+$', data) == None:
|
||||||
raise ValidationError(_('Invalid characters in base64 hash'))
|
raise ValidationError(_('Invalid characters in base64 hash'))
|
||||||
# base64-validity test
|
# base64-validity test
|
||||||
if length > 516:
|
if length > 516:
|
||||||
@ -104,6 +104,9 @@ def validate_b64hash(data, check_uniq=True):
|
|||||||
# base64-i2p
|
# base64-i2p
|
||||||
if length == 516 and re.match(r'[a-zA-Z0-9\-~]+AA$', data) == None:
|
if length == 516 and re.match(r'[a-zA-Z0-9\-~]+AA$', data) == None:
|
||||||
raise ValidationError(_('Invalid base64 hash'))
|
raise ValidationError(_('Invalid base64 hash'))
|
||||||
|
# check ECDSA validity
|
||||||
|
if length == 524 and re.match(r'[a-zA-Z0-9\-~]+AEAAEAAA==$', data) == None:
|
||||||
|
raise ValidationError(_('Invalid base64 ECDSA hash'))
|
||||||
if check_uniq == True:
|
if check_uniq == True:
|
||||||
# Avoid adding non-unique hashes
|
# Avoid adding non-unique hashes
|
||||||
qs = i2phost.objects.filter(b64hash=data)
|
qs = i2phost.objects.filter(b64hash=data)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user