11from typing import Any
2- import multibase
2+
3+ import multibase
34import multihash
45
56from ..codecs import CodecBase
6- from ..exceptions import BinaryParseError
77
88SIZE = - 1
99IS_PATH = False
1010
11+
1112class Codec (CodecBase ):
1213 """
1314 Codec for certificate hashes (certhash).
14-
15+
1516 A certhash is a multihash of a certificate, encoded as a multibase string
1617 using the 'base64url' encoding.
1718 """
18-
19+
1920 SIZE = SIZE
2021 IS_PATH = IS_PATH
21-
22+
2223 def validate (self , b : bytes ) -> None :
2324 """
2425 Validates that the byte representation is a valid multihash.
@@ -32,7 +33,7 @@ def validate(self, b: bytes) -> None:
3233 try :
3334 multihash .decode (b )
3435 except Exception as e :
35- raise ValueError (f "Invalid certhash: not a valid multihash" ) from e
36+ raise ValueError ("Invalid certhash: not a valid multihash" ) from e
3637
3738 def to_bytes (self , proto : Any , string : str ) -> bytes :
3839 """
@@ -60,7 +61,7 @@ def to_bytes(self, proto: Any, string: str) -> bytes:
6061 # Validate that the decoded bytes are a valid multihash.
6162 self .validate (decoded_bytes )
6263 return decoded_bytes
63-
64+
6465 def to_string (self , proto : Any , buf : bytes ) -> str :
6566 """
6667 Converts the raw multihash bytes of a certhash to its string form.
@@ -80,5 +81,5 @@ def to_string(self, proto: Any, buf: bytes) -> str:
8081
8182 # Encode the bytes using base64url, which is standard for certhash.
8283 # The result from `multibase.encode` is bytes, so we decode to a string.
83- encoded_string = multibase .encode (' base64url' , buf )
84- return encoded_string .decode (' utf-8' )
84+ encoded_string = multibase .encode (" base64url" , buf )
85+ return encoded_string .decode (" utf-8" )
0 commit comments