0

I am working in a c++ project where I have to use < openssl/sha.h> and I am using in particular the SHA1 function. My problem is, that the function receives unsigned char[], and I need to get processed parameters passed as arguments to the program:

int main(int argc, char* argv[])
{

  unsigned char message[] = argv[1];

  /* program continues using message */

}

And the error I am getting is the following:

error: array initializer must be an initializer list or string literal
const unsigned char message[] = argv[1];
                    ^

So I am not getting to cast appropiately the argument input to the 'message' variable, to make the appropiate call to SHA1 function.

Thanks!!

9uzman7
  • 409
  • 8
  • 19

1 Answers1

2

An array cannot be initialized from a pointer. You should probably use an unsigned char * instead:

unsigned char *message = reinterpret_cast<unsigned char *>(argv[1]);
Sam Varshavchik
  • 114,536
  • 5
  • 94
  • 148