|
17 | 17 | from packaging.utils import parse_sdist_filename, parse_wheel_filename
|
18 | 18 | from pyasn1.codec.der.decoder import decode as der_decode
|
19 | 19 | from pyasn1.type.char import UTF8String
|
20 |
| -from pydantic import Base64Encoder, BaseModel, ConfigDict, EncodedBytes, Field, field_validator |
| 20 | +from pydantic import Base64Bytes, BaseModel, ConfigDict, Field, field_validator |
21 | 21 | from pydantic.alias_generators import to_snake
|
22 | 22 | from pydantic_core import ValidationError
|
23 | 23 | from sigstore._utils import _sha256_streaming
|
|
38 | 38 | from sigstore.verify.policy import VerificationPolicy
|
39 | 39 |
|
40 | 40 |
|
41 |
| -class Base64EncoderSansNewline(Base64Encoder): |
42 |
| - r"""A Base64Encoder that doesn't insert newlines when encoding. |
43 |
| -
|
44 |
| - Pydantic's Base64Bytes type inserts newlines b'\n' every 76 characters because they |
45 |
| - use `base64.encodebytes()` instead of `base64.b64encode()`. Pydantic maintainers |
46 |
| - have stated that they won't fix this, and that users should work around it by |
47 |
| - defining their own Base64 type with a custom encoder. |
48 |
| - See https://github.com/pydantic/pydantic/issues/9072 for more details. |
49 |
| - """ |
50 |
| - |
51 |
| - @classmethod |
52 |
| - def encode(cls, value: bytes) -> bytes: |
53 |
| - """Encode bytes to base64.""" |
54 |
| - return base64.b64encode(value) |
55 |
| - |
56 |
| - @classmethod |
57 |
| - def decode(cls, value: bytes) -> bytes: |
58 |
| - """Decode base64 bytes.""" |
59 |
| - return base64.b64decode(value, validate=True) |
60 |
| - |
61 |
| - |
62 |
| -Base64Bytes = Annotated[bytes, EncodedBytes(encoder=Base64EncoderSansNewline)] |
63 |
| - |
64 |
| - |
65 | 41 | class Distribution(BaseModel):
|
66 | 42 | """Represents a Python package distribution.
|
67 | 43 |
|
|
0 commit comments