| 45 | class Hash(object): |
| 46 | @classmethod |
| 47 | def create(cls, hasher): |
| 48 | # type: (Hasher) -> Hash |
| 49 | |
| 50 | # The fingerprint encoding is defined for PEP-376 RECORD files as `urlsafe-base64-nopad` |
| 51 | # which is fully spelled out in code in PEP-427: |
| 52 | # + https://peps.python.org/pep-0376/#record |
| 53 | # + https://peps.python.org/pep-0427/#appendix |
| 54 | fingerprint = base64.urlsafe_b64encode(hasher.digest()).rstrip(b"=") |
| 55 | |
| 56 | # N.B.: The algorithm is all caps under Python 2.7, but lower case under Python 3; so we |
| 57 | # normalize. |
| 58 | alg = hasher.name.lower() |
| 59 | |
| 60 | return cls(value="{alg}={hash}".format(alg=alg, hash=fingerprint.decode("ascii"))) |
| 61 | |
| 62 | value = attr.ib() # type: str |
| 63 | |