Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix signatures of XrdCryptosslRSA Export methods #707

Merged
merged 1 commit into from
May 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
40 changes: 18 additions & 22 deletions src/XrdCrypto/XrdCryptosslRSA.cc
Original file line number Diff line number Diff line change
Expand Up @@ -361,11 +361,11 @@ int XrdCryptosslRSA::GetPublen()
return publen;
}
//_____________________________________________________________________________
int XrdCryptosslRSA::ExportPublic(char *&out, int)
int XrdCryptosslRSA::ExportPublic(char *out, int)
{
// Export the public key into buffer out. The length of the buffer should be
// at least GetPublen()+1 bytes. If out=0 the buffer is m-allocated internally
// and should be freed by the caller.
// at least GetPublen()+1 bytes. The buffer out must be passed-by and it
// responsability-of the caller.
// Return 0 in case of success, -1 in case of failure
EPNAME("RSA::ExportPublic");

Expand All @@ -375,6 +375,12 @@ int XrdCryptosslRSA::ExportPublic(char *&out, int)
return -1;
}

// Check output buffer
if (!out) {
DEBUG("output buffer undefined!");
return -1;
}

// Bio for exporting the pub key
BIO *bkey = BIO_new(BIO_s_mem());

Expand All @@ -389,14 +395,6 @@ int XrdCryptosslRSA::ExportPublic(char *&out, int)
return -1;
}

// Check output buffer
if (!out) {
out = (char *) malloc(lbio+1);
if (!out) {
DEBUG("problems allocating output buffer");
return -1;
}
}
// Read key from BIO to buf
memcpy(out, cbio, lbio);
// Null terminate
Expand Down Expand Up @@ -426,11 +424,11 @@ int XrdCryptosslRSA::GetPrilen()
}

//_____________________________________________________________________________
int XrdCryptosslRSA::ExportPrivate(char *&out, int)
int XrdCryptosslRSA::ExportPrivate(char *out, int)
{
// Export the private key into buffer out. The length of the buffer should be
// at least GetPrilen()+1 bytes. If out=0 the buffer is m-allocated internally
// and should be freed by the caller.
// at least GetPrilen()+1 bytes. The buffer out must be passed-by and it
// responsability-of the caller.
// Return 0 in case of success, -1 in case of failure
EPNAME("RSA::ExportPrivate");

Expand All @@ -440,6 +438,12 @@ int XrdCryptosslRSA::ExportPrivate(char *&out, int)
return -1;
}

// Check output buffer
if (!out) {
DEBUG("output buffer undefined!");
return -1;
}

// Bio for exporting the pub key
BIO *bkey = BIO_new(BIO_s_mem());

Expand All @@ -454,14 +458,6 @@ int XrdCryptosslRSA::ExportPrivate(char *&out, int)
return -1;
}

// Check output buffer
if (!out) {
out = (char *) malloc(lbio+1);
if (!out) {
DEBUG("problems allocating output buffer");
return -1;
}
}
// Read key from BIO to buf
memcpy(out, cbio, lbio);
// Null terminate
Expand Down
4 changes: 2 additions & 2 deletions src/XrdCrypto/XrdCryptosslRSA.hh
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ public:

// Import / Export methods
int ImportPublic(const char *in, int lin);
int ExportPublic(char *&out, int lout);
int ExportPublic(char *out, int lout);
int ImportPrivate(const char *in, int lin);
int ExportPrivate(char *&out, int lout);
int ExportPrivate(char *out, int lout);

// Encryption / Decryption methods
int EncryptPrivate(const char *in, int lin, char *out, int lout);
Expand Down