Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
opendht
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
savoirfairelinux
opendht
Commits
6e01255b
Commit
6e01255b
authored
10 years ago
by
Adrien Béraud
Browse files
Options
Downloads
Patches
Plain Diff
crypto: add Certificate::toString
parent
13902b0f
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
include/opendht/crypto.h
+6
-1
6 additions, 1 deletion
include/opendht/crypto.h
src/crypto.cpp
+14
-0
14 additions, 0 deletions
src/crypto.cpp
with
20 additions
and
1 deletion
include/opendht/crypto.h
+
6
−
1
View file @
6e01255b
...
@@ -107,7 +107,7 @@ struct PrivateKey
...
@@ -107,7 +107,7 @@ struct PrivateKey
/**
/**
* Generate a new RSA key pair
* Generate a new RSA key pair
* @param key_length : size of the modulus in bits
* @param key_length : size of the modulus in bits
* Recommended values:
2048,
4096, 8192
* Recommended values: 4096, 8192
*/
*/
static
PrivateKey
generate
(
unsigned
key_length
=
4096
);
static
PrivateKey
generate
(
unsigned
key_length
=
4096
);
...
@@ -139,6 +139,11 @@ struct Certificate : public Serializable {
...
@@ -139,6 +139,11 @@ struct Certificate : public Serializable {
std
::
string
getUID
()
const
;
std
::
string
getUID
()
const
;
/**
* PEM encoded certificate
*/
std
::
string
toString
()
const
;
gnutls_x509_crt_t
cert
{};
gnutls_x509_crt_t
cert
{};
private
:
private
:
Certificate
(
const
Certificate
&
)
=
delete
;
Certificate
(
const
Certificate
&
)
=
delete
;
...
...
This diff is collapsed.
Click to expand it.
src/crypto.cpp
+
14
−
0
View file @
6e01255b
...
@@ -416,6 +416,20 @@ Certificate::getUID() const
...
@@ -416,6 +416,20 @@ Certificate::getUID() const
return
uid
;
return
uid
;
}
}
std
::
string
Certificate
::
toString
()
const
{
std
::
string
str
;
size_t
buf_sz
=
8192
;
str
.
resize
(
buf_sz
);
int
err
=
gnutls_x509_crt_export
(
cert
,
GNUTLS_X509_FMT_PEM
,
&
(
*
str
.
begin
()),
&
buf_sz
);
if
(
err
!=
GNUTLS_E_SUCCESS
)
{
std
::
cerr
<<
"Could not export certificate - "
<<
gnutls_strerror
(
err
)
<<
std
::
endl
;
}
str
.
resize
(
buf_sz
);
return
str
;
}
PrivateKey
PrivateKey
PrivateKey
::
generate
(
unsigned
key_length
)
PrivateKey
::
generate
(
unsigned
key_length
)
{
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment