-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use pyasn1-fasder for ASN.1 DER decoding (#98)
* Use pyasn1-fasder decoding by default * Delete references to removed validations * Change update template * Update CHANGELOG.md * Add trailing newline
- Loading branch information
Showing
26 changed files
with
120 additions
and
269 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
0.11.3 | ||
0.11.4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,3 @@ | ||
from pyasn1.codec.der.encoder import encode | ||
from pyasn1.type.univ import BitString | ||
|
||
from pkilint import validation | ||
|
||
|
||
class NamedBitStringMinimalEncodingValidator(validation.Validator): | ||
VALIDATION_BIT_STRING_NOT_MINIMALLY_ENCODED = validation.ValidationFinding( | ||
validation.ValidationFindingSeverity.ERROR, | ||
'itu.bitstring_not_der_encoded' | ||
) | ||
|
||
def __init__(self): | ||
super().__init__( | ||
validations=[self.VALIDATION_BIT_STRING_NOT_MINIMALLY_ENCODED], | ||
pdu_class=BitString, | ||
predicate=lambda n: any(n.pdu.namedValues) | ||
) | ||
|
||
def validate(self, node): | ||
# extract values then re-encode | ||
|
||
asserted_values = ','.join((k for k in node.pdu.namedValues.keys() if has_named_bit(node, k))) | ||
|
||
encoded = encode(node.pdu) | ||
|
||
new_encoded = encode(type(node.pdu)(asserted_values), asn1Spec=node.pdu) | ||
|
||
if encoded != new_encoded: | ||
encoded_hex = encoded.hex() | ||
new_encoded_hex = new_encoded.hex() | ||
|
||
raise validation.ValidationFindingEncountered( | ||
self.VALIDATION_BIT_STRING_NOT_MINIMALLY_ENCODED, | ||
f'Expected: "{new_encoded_hex}", actual: "{encoded_hex}"' | ||
) | ||
|
||
|
||
def has_named_bit(node, bit_name): | ||
bit = node.pdu.namedValues[bit_name] | ||
return len(node.pdu) > bit and node.pdu[bit] != 0 |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.