Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions include/c2pa.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ namespace c2pa
{
private:
C2paReader *c2pa_reader;
CppIStream *cpp_stream = NULL;
CppIStream *cpp_stream = nullptr;

public:
/// @brief Create a Reader from a stream.
Expand Down Expand Up @@ -257,7 +257,7 @@ namespace c2pa

Signer(C2paSigner *signer) : signer(signer) {}

Signer(const string &alg, const string &sign_cert, const string&private_key, const string &tsa_uri = NULL);
Signer(const string &alg, const string &sign_cert, const string&private_key, const string &tsa_uri = {});
Copy link
Collaborator

@dyro dyro Nov 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer to change this to the following, if we are going to make a change to the API:

Header

Signer::Signer(const string &alg, const string &sign_cert, const string &private_key, optional<std::string> tsa_uri)

Implementation

// implementation then would be something like this:
Signer::Signer(const string &alg, const string &sign_cert, const string &private_key,
               optional<std::string> tsa_uri) {
    auto info = C2paSignerInfo{
        alg.c_str(),
        sign_cert.c_str(),
        private_key.c_str(),
        tsa_uri.has_value() ? tsa_uri->c_str() : nullptr
    };
    signer = c2pa_signer_from_info(&info);
}

Since we are already changing the API, let's make it more semantically correct. Also, using a string as the default changes the behavior of the API. Using a zero length string would mean we are passing a non-nullptr to the Rust code, which may change the behavior of the rust sdk. Lemme know what you think!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already include in the headers and use it in other apis, so this is the right approach here.
FYI, we are a little inconsistent, usually just referring to optional instead of std:optional in the source.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey. Thanks for the comment. Just gave it a quick test, and you are absolutely right. The rust sdk does in fact treat the nullptr as the absence of the value, but treats an empty string as a uri and crashes when it tries to make a request to that uri.

I will patch the commit to use an optional instead.

I also found that none of the tests actually attempt to construct the Signer with default tsa_uri, and doing this with current implementation results in a segfault on the c++ side. Shall we add a test to capture this?


~Signer();

Expand Down
Loading