Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8506405
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T02:34:55+00:00 2026-06-11T02:34:55+00:00

I want to call this function from OpenSSL library defined with prototy below: X509

  • 0

I want to call this function from OpenSSL library defined with prototy below:

X509 *d2i_X509(X509 **px, const unsigned char **in, int len);

The second parameter in is defined as a const unsigned char ** because:

  • d2i_X509 won’t modify the data in the buffer pointed to by *in
  • *in will be incremented by the amount of data parsed from the buffer.

Now this prototype is a problem, because as far as I see the function can’t be called the following way which as far as I understand the API is the normal way to call it (error management code removed to make things simpler):

unsigned char buffer[2048];
unsigned char * end = buffer;
unsigned char * p = buffer;

end += read(fd, p, 2048);
certlen1 = parseint(&p);
X509 * cert1 = d2i_x509(NULL, &p, certlen1);
certlen2 = parseint(&p);
X509 * cert2 = d2i_x509(NULL, &p, certlen2);

If I try to compile the above code, it says:

error: invalid conversion from 'unsigned char**' to 'const unsigned char**'

I understand the rationale of the message (explained here for instance), but in this particular case this rationale does not apply as the function states in it’s documentation it will only increment the value of *in, never assign an unrelated pointer to it.

I can’t change type of p to const unsigned char * because the code above is actually simplified, the pointer is hidden behind some abstract IO object performing both reading and writing. The good point with the previous IO object is that is keeps symmetric reading and writing code together, it is possible to use two separate pointers for reading and writing in my IO object, but overall benefice of doing that is really small (if not negative) and add much syntaxic noise. Also having that kind of deep internal change in an IO object forced by some external unrelated API call, looks really stretching.

A solution could be to perform a cast or even to not use the returned pointer value at all (as I have the size parameter), but it does not feels right either. It seems either the prototype of d2i_X509 does not contains enough information, or that the const checking rule of the compiler is too strict in such case.

How should such API be called from C++ ? For now I just will use a cast as I feel it is the lesser evil, but is there any better way ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T02:34:56+00:00Added an answer on June 11, 2026 at 2:34 am

    First, the += in this code doesn’t make much sense:

    p += read(fd, p, 2048);
    

    You’re modifying p to point just past the data you just read, so d2i_x509 will be reading junk.

    I’d do it like this:

    unsigned char buffer[2048];
    int n = read(fd, buffer, 2048);
    if (n < 0) ..error..;
    const unsigned char * p = buffer;
    X509 * cert1 = d2i_x509(NULL, &p, certlen1);
    X509 * cert2 = d2i_x509(NULL, &p, certlen2);
    int used = p - buffer;  // # of bytes actually parsed by the two calls
    

    Any future changes can be done to buffer directly.

    Edit:

    Ok, then replace this:

    X509 * cert1 = d2i_x509(NULL, &p, certlen1);
    

    with this:

    {
      const unsigned char *q = p;
      X509 * cert1 = d2i_x509(NULL, &q, certlen1);
      p += q - p;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to call a function from a file using href. Below is my
I call this function from another page Redirect($loc); and I want it to redirect
I have a UDF in sql server. I want to call this function at
If I want to trigger an error in my interpreter I call this function:
I'm trying to call a function that contains jQuery code. I want this function
I want to use jquery delegate to call a function, and this works fine:
Possible Duplicate: lambdas require capturing 'this' to call static member function? I want to
Actually I have some MVC3 Applications and I want to call this applications from
In my application I want to call service from Receiver. This is my NotificationReceiver.java
Is there a way to call a C++ shared library function from within a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.