Skip to content

Commit 724a88a

Browse files
committed
fix: Move mapping closer to enum
1 parent 3fc818f commit 724a88a

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

src/c2pa/c2pa.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,19 @@ class C2paSigningAlg(enum.IntEnum):
123123
ED25519 = 6
124124

125125

126+
# Mapping from C2paSigningAlg enum to string representation,
127+
# as the enum value currently maps by default to an integer value.
128+
_ALG_MAPPING = {
129+
C2paSigningAlg.ES256: b"es256",
130+
C2paSigningAlg.ES384: b"es384",
131+
C2paSigningAlg.ES512: b"es512",
132+
C2paSigningAlg.PS256: b"ps256",
133+
C2paSigningAlg.PS384: b"ps384",
134+
C2paSigningAlg.PS512: b"ps512",
135+
C2paSigningAlg.ED25519: b"ed25519",
136+
}
137+
138+
126139
# Define callback types
127140
ReadCallback = ctypes.CFUNCTYPE(
128141
ctypes.c_ssize_t,
@@ -205,18 +218,6 @@ class C2paSignerInfo(ctypes.Structure):
205218
("ta_url", ctypes.c_char_p),
206219
]
207220

208-
# Mapping from C2paSigningAlg enum to string representation,
209-
# as the enum value currently maps by default to an integer value.
210-
_ALG_MAPPING = {
211-
C2paSigningAlg.ES256: b"es256",
212-
C2paSigningAlg.ES384: b"es384",
213-
C2paSigningAlg.ES512: b"es512",
214-
C2paSigningAlg.PS256: b"ps256",
215-
C2paSigningAlg.PS384: b"ps384",
216-
C2paSigningAlg.PS512: b"ps512",
217-
C2paSigningAlg.ED25519: b"ed25519",
218-
}
219-
220221
def __init__(self, alg=None, sign_cert=None, private_key=None, ta_url=None):
221222
"""Initialize C2paSignerInfo with optional parameters.
222223
@@ -231,7 +232,7 @@ def __init__(self, alg=None, sign_cert=None, private_key=None, ta_url=None):
231232
if alg is not None:
232233
if isinstance(alg, C2paSigningAlg):
233234
# Convert enum to string representation
234-
alg_str = self._ALG_MAPPING.get(alg)
235+
alg_str = _ALG_MAPPING.get(alg)
235236
if alg_str is None:
236237
raise ValueError(f"Unsupported signing algorithm: {alg}")
237238
alg = alg_str

0 commit comments

Comments
 (0)