Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
mtxclient
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Nheko Reborn
mtxclient
Commits
266e48c4
Commit
266e48c4
authored
4 years ago
by
Nicolas Werner
Browse files
Options
Downloads
Patches
Plain Diff
Add base58 decoding
parent
68e043e1
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
include/mtxclient/crypto/utils.hpp
+3
-0
3 additions, 0 deletions
include/mtxclient/crypto/utils.hpp
lib/crypto/client.cpp
+0
-1
0 additions, 1 deletion
lib/crypto/client.cpp
lib/crypto/encoding.cpp
+44
-0
44 additions, 0 deletions
lib/crypto/encoding.cpp
tests/crypto.cpp
+8
-0
8 additions, 0 deletions
tests/crypto.cpp
with
55 additions
and
1 deletion
include/mtxclient/crypto/utils.hpp
+
3
−
0
View file @
266e48c4
...
...
@@ -106,5 +106,8 @@ bin2base64_urlsafe_unpadded(const std::string &bin);
std
::
string
bin2base58
(
const
std
::
string
&
bin
);
std
::
string
base582bin
(
const
std
::
string
&
bin
);
}
// namespace crypto
}
// namespace mtx
This diff is collapsed.
Click to expand it.
lib/crypto/client.cpp
+
0
−
1
View file @
266e48c4
...
...
@@ -641,4 +641,3 @@ mtx::crypto::decrypt_exported_sessions(const std::string &data, std::string pass
std
::
string
plaintext
(
decrypted
.
begin
(),
decrypted
.
end
());
return
json
::
parse
(
plaintext
);
}
This diff is collapsed.
Click to expand it.
lib/crypto/encoding.cpp
+
44
−
0
View file @
266e48c4
#include
<algorithm>
#include
<array>
#include
<string>
#include
<vector>
...
...
@@ -87,6 +88,43 @@ encode_base58(const std::array<char, 58> &alphabet, const std::string &input)
return
result
;
}
inline
std
::
string
decode_base58
(
const
std
::
array
<
uint8_t
,
256
>
&
reverse_alphabet
,
const
std
::
string
&
input
)
{
std
::
string
result
;
if
(
input
.
empty
())
return
result
;
result
.
reserve
(
input
.
size
()
*
733
/
1000
+
1
);
// result.push_back(0);
for
(
uint8_t
b
:
input
)
{
if
(
b
==
' '
)
continue
;
if
(
b
==
0xff
)
return
""
;
uint32_t
carry
=
reverse_alphabet
[
b
];
for
(
std
::
size_t
j
=
0
;
j
<
result
.
size
();
j
++
)
{
carry
+=
static_cast
<
uint8_t
>
(
result
[
j
])
*
58
;
result
[
j
]
=
static_cast
<
uint8_t
>
(
carry
%
0x100
);
carry
/=
0x100
;
}
while
(
carry
>
0
)
{
result
.
push_back
(
static_cast
<
uint8_t
>
(
carry
%
0x100
));
carry
/=
0x100
;
}
}
for
(
size_t
i
=
0
;
i
<
input
.
length
()
&&
input
[
i
]
==
'1'
;
i
++
)
result
.
push_back
(
0
);
std
::
reverse
(
result
.
begin
(),
result
.
end
());
return
result
;
}
template
<
bool
pad
>
inline
std
::
string
encode_base64
(
const
std
::
array
<
char
,
64
>
&
alphabet
,
std
::
string
input
)
...
...
@@ -210,5 +248,11 @@ bin2base58(const std::string &bin)
{
return
encode_base58
(
base58_alphabet
,
bin
);
}
std
::
string
base582bin
(
const
std
::
string
&
bin
)
{
return
decode_base58
(
base58_to_int
,
bin
);
}
}
}
This diff is collapsed.
Click to expand it.
tests/crypto.cpp
+
8
−
0
View file @
266e48c4
...
...
@@ -184,6 +184,14 @@ TEST(Base58, EncodingDecoding)
EXPECT_EQ
(
bin2base58
(
"foob"
),
"3csAg9"
);
EXPECT_EQ
(
bin2base58
(
"fooba"
),
"CZJRhmz"
);
EXPECT_EQ
(
bin2base58
(
"foobar"
),
"t1Zv2yaZ"
);
EXPECT_EQ
(
""
,
base582bin
(
""
));
EXPECT_EQ
(
"f"
,
base582bin
(
"2m"
));
EXPECT_EQ
(
"fo"
,
base582bin
(
"8o8"
));
EXPECT_EQ
(
"foo"
,
base582bin
(
"bQbp"
));
EXPECT_EQ
(
"foob"
,
base582bin
(
"3csAg9"
));
EXPECT_EQ
(
"fooba"
,
base582bin
(
"CZJRhmz"
));
EXPECT_EQ
(
"foobar"
,
base582bin
(
"t1Zv2yaZ"
));
}
TEST
(
ExportSessions
,
EncryptDecrypt
)
...
...
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