Skip to content

Commit 385f4f6

Browse files
committed
fix: Merge commit
2 parents a0ca592 + 6f7e8d3 commit 385f4f6

File tree

3 files changed

+57
-9
lines changed

3 files changed

+57
-9
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ jobs:
452452
run: |
453453
echo "Downloaded Artifacts"
454454
ls -la dist/
455-
- name: Publish to TestPyPI
455+
- name: Publish to PyPI
456456
uses: pypa/gh-action-pypi-publish@release/v1
457457
with:
458458
packages-dir: dist

src/c2pa/c2pa.py

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,19 @@ class C2paSigningAlg(enum.IntEnum):
135135
ED25519 = 6
136136

137137

138+
# Mapping from C2paSigningAlg enum to string representation,
139+
# as the enum value currently maps by default to an integer value.
140+
_ALG_TO_STRING_BYTES_MAPPING = {
141+
C2paSigningAlg.ES256: b"es256",
142+
C2paSigningAlg.ES384: b"es384",
143+
C2paSigningAlg.ES512: b"es512",
144+
C2paSigningAlg.PS256: b"ps256",
145+
C2paSigningAlg.PS384: b"ps384",
146+
C2paSigningAlg.PS512: b"ps512",
147+
C2paSigningAlg.ED25519: b"ed25519",
148+
}
149+
150+
138151
# Define callback types
139152
ReadCallback = ctypes.CFUNCTYPE(
140153
ctypes.c_ssize_t,
@@ -218,6 +231,45 @@ class C2paSignerInfo(ctypes.Structure):
218231
("ta_url", ctypes.c_char_p),
219232
]
220233

234+
def __init__(self, alg, sign_cert, private_key, ta_url):
235+
"""Initialize C2paSignerInfo with optional parameters.
236+
237+
Args:
238+
alg: The signing algorithm, either as a C2paSigningAlg enum or string or bytes
239+
(will be converted accordingly to bytes for native library use)
240+
sign_cert: The signing certificate as a string
241+
private_key: The private key as a string
242+
ta_url: The timestamp authority URL as bytes
243+
"""
244+
# Handle alg parameter: can be C2paSigningAlg enum or string (or bytes), convert as needed
245+
if isinstance(alg, C2paSigningAlg):
246+
# Convert enum to string representation
247+
alg_str = _ALG_TO_STRING_BYTES_MAPPING.get(alg)
248+
if alg_str is None:
249+
raise ValueError(f"Unsupported signing algorithm: {alg}")
250+
alg = alg_str
251+
elif isinstance(alg, str):
252+
# String to bytes, as requested by native lib
253+
alg = alg.encode('utf-8')
254+
elif isinstance(alg, bytes):
255+
# In bytes already
256+
pass
257+
else:
258+
raise TypeError(f"alg must be C2paSigningAlg enum, string, or bytes, got {type(alg)}")
259+
260+
# Handle ta_url parameter: allow string or bytes, convert string to bytes as needed
261+
if isinstance(ta_url, str):
262+
# String to bytes, as requested by native lib
263+
ta_url = ta_url.encode('utf-8')
264+
elif isinstance(ta_url, bytes):
265+
# In bytes already
266+
pass
267+
else:
268+
raise TypeError(f"ta_url must be string or bytes, got {type(ta_url)}")
269+
270+
# Call parent constructor with processed values
271+
super().__init__(alg, sign_cert, private_key, ta_url)
272+
221273

222274
class C2paReader(ctypes.Structure):
223275
"""Opaque structure for reader context."""
@@ -2105,7 +2157,7 @@ def _sign_internal(
21052157
dest_stream: The destination stream, as Stream(BytesIO)
21062158
21072159
Returns:
2108-
A tuple of (size of C2PA data, manifest bytes)
2160+
Manifest bytes
21092161
21102162
Raises:
21112163
C2paError: If there was an error during signing

src/c2pa/lib.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,9 @@
1616
# Debug flag for library loading
1717
DEBUG_LIBRARY_LOADING = False
1818

19-
# Configure logging
20-
logging.basicConfig(
21-
level=logging.INFO,
22-
format='%(asctime)s - %(levelname)s - %(message)s',
23-
force=True # Force configuration even if already configured
24-
)
25-
logger = logging.getLogger(__name__)
19+
# Create a module-specific logger with NullHandler to avoid interfering with global configuration
20+
logger = logging.getLogger("c2pa")
21+
logger.addHandler(logging.NullHandler())
2622

2723

2824
class CPUArchitecture(Enum):

0 commit comments

Comments
 (0)