Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
V
Vereign Client Library
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Code
Vereign Client Library
Commits
e8f39da1
Commit
e8f39da1
authored
6 years ago
by
Alexander Holodov
Browse files
Options
Downloads
Patches
Plain Diff
18 prevent useless allocates
parent
75fa0992
No related branches found
No related tags found
1 merge request
!19
18: added c++ library
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
cpp/secret_store.hpp
+10
-10
10 additions, 10 deletions
cpp/secret_store.hpp
with
10 additions
and
10 deletions
cpp/secret_store.hpp
+
10
−
10
View file @
e8f39da1
...
...
@@ -103,17 +103,17 @@ std::vector<unsigned char> generateRandomBytes(int size) {
}
std
::
string
toHex
(
const
std
::
vector
<
unsigned
char
>
&
data
)
{
std
::
unique_ptr
<
unsigned
char
[]
>
hex
(
new
unsigned
char
[
((
data
.
size
()
+
2
)
/
3
)
*
4
+
1
]
);
int
len
=
EVP_EncodeBlock
(
hex
.
get
()
,
data
.
data
(),
data
.
size
());
std
::
string
hex
(
((
data
.
size
()
+
2
)
/
3
)
*
4
+
1
,
0
);
int
len
=
EVP_EncodeBlock
(
(
unsigned
char
*
)
&
hex
[
0
]
,
data
.
data
(),
data
.
size
());
if
(
len
<
0
)
{
throw
std
::
runtime_error
(
"can't encode salt"
);
}
return
std
::
string
((
const
char
*
)
hex
.
get
())
;
return
hex
;
}
std
::
vector
<
unsigned
char
>
toBin
(
const
std
::
string
&
data
)
{
std
::
unique_pt
r
<
unsigned
char
[]
>
bin
(
new
unsigned
char
[
data
.
length
()
]
);
auto
len
=
EVP_DecodeBlock
(
(
unsigned
char
*
)
bin
.
get
()
,
(
const
unsigned
char
*
)
data
.
c_str
(),
data
.
length
());
std
::
vecto
r
<
unsigned
char
>
bin
(
data
.
length
());
auto
len
=
EVP_DecodeBlock
(
&
bin
[
0
]
,
(
const
unsigned
char
*
)
data
.
c_str
(),
data
.
length
());
for
(
auto
rit
=
data
.
rbegin
();
rit
!=
data
.
rend
();
++
rit
)
{
if
(
*
rit
!=
'='
)
{
break
;
...
...
@@ -125,7 +125,8 @@ std::vector<unsigned char> toBin(const std::string &data) {
throw
std
::
runtime_error
(
"can't decode base64"
);
}
return
std
::
vector
<
unsigned
char
>
((
unsigned
char
*
)
bin
.
get
(),
(
unsigned
char
*
)
bin
.
get
()
+
len
);
bin
.
resize
(
len
);
return
bin
;
}
std
::
string
SecretStore
::
encrypt
(
const
std
::
vector
<
unsigned
char
>
&
value
,
const
std
::
string
&
pass
)
{
...
...
@@ -182,10 +183,9 @@ std::vector<unsigned char> SecretStore::crypt(AES_KEY *aes_key, const std::vecto
memset
(
ecount_buf
,
0
,
sizeof
(
ecount_buf
));
unsigned
int
num
=
0
;
std
::
unique_ptr
<
unsigned
char
[]
>
output
(
new
unsigned
char
[
input
.
size
()]);
AES_ctr128_encrypt
(
input
.
data
(),
output
.
get
(),
input
.
size
(),
aes_key
,
ivec
,
ecount_buf
,
&
num
);
return
std
::
vector
<
unsigned
char
>
((
unsigned
char
*
)
output
.
get
(),
(
unsigned
char
*
)
output
.
get
()
+
input
.
size
());
std
::
vector
<
unsigned
char
>
output
(
input
.
size
());
AES_ctr128_encrypt
(
input
.
data
(),
&
output
[
0
],
input
.
size
(),
aes_key
,
ivec
,
ecount_buf
,
&
num
);
return
output
;
}
...
...
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