Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
godot
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
community
godot
Commits
24c52f1c
Commit
24c52f1c
authored
Jul 02, 2019
by
Fabio Alessandrelli
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add b64 to string helper in CryptoCore
parent
6c512e21
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
36 deletions
+18
-36
core_bind.cpp
core/bind/core_bind.cpp
+6
-36
crypto_core.cpp
core/math/crypto_core.cpp
+11
-0
crypto_core.h
core/math/crypto_core.h
+1
-0
No files found.
core/bind/core_bind.cpp
View file @
24c52f1c
...
@@ -2432,16 +2432,8 @@ String _Marshalls::variant_to_base64(const Variant &p_var, bool p_full_objects)
...
@@ -2432,16 +2432,8 @@ String _Marshalls::variant_to_base64(const Variant &p_var, bool p_full_objects)
err
=
encode_variant
(
p_var
,
&
w
[
0
],
len
,
p_full_objects
);
err
=
encode_variant
(
p_var
,
&
w
[
0
],
len
,
p_full_objects
);
ERR_FAIL_COND_V
(
err
!=
OK
,
""
);
ERR_FAIL_COND_V
(
err
!=
OK
,
""
);
int
b64len
=
len
/
3
*
4
+
4
+
1
;
String
ret
=
CryptoCore
::
b64_encode_str
(
&
w
[
0
],
len
);
PoolVector
<
uint8_t
>
b64buff
;
ERR_FAIL_COND_V
(
ret
==
""
,
ret
);
b64buff
.
resize
(
b64len
);
PoolVector
<
uint8_t
>::
Write
w64
=
b64buff
.
write
();
size_t
strlen
=
0
;
ERR_FAIL_COND_V
(
CryptoCore
::
b64_encode
(
&
w64
[
0
],
b64len
,
&
strlen
,
&
w
[
0
],
len
)
!=
OK
,
String
());
//OS::get_singleton()->print("len is %i, vector size is %i\n", b64len, strlen);
w64
[
strlen
]
=
0
;
String
ret
=
(
char
*
)
&
w64
[
0
];
return
ret
;
return
ret
;
};
};
...
@@ -2467,19 +2459,8 @@ Variant _Marshalls::base64_to_variant(const String &p_str, bool p_allow_objects)
...
@@ -2467,19 +2459,8 @@ Variant _Marshalls::base64_to_variant(const String &p_str, bool p_allow_objects)
String
_Marshalls
::
raw_to_base64
(
const
PoolVector
<
uint8_t
>
&
p_arr
)
{
String
_Marshalls
::
raw_to_base64
(
const
PoolVector
<
uint8_t
>
&
p_arr
)
{
int
len
=
p_arr
.
size
();
String
ret
=
CryptoCore
::
b64_encode_str
(
p_arr
.
read
().
ptr
(),
p_arr
.
size
());
PoolVector
<
uint8_t
>::
Read
r
=
p_arr
.
read
();
ERR_FAIL_COND_V
(
ret
==
""
,
ret
);
int
b64len
=
len
/
3
*
4
+
4
+
1
;
PoolVector
<
uint8_t
>
b64buff
;
b64buff
.
resize
(
b64len
);
PoolVector
<
uint8_t
>::
Write
w64
=
b64buff
.
write
();
size_t
strlen
=
0
;
ERR_FAIL_COND_V
(
CryptoCore
::
b64_encode
(
&
w64
[
0
],
b64len
,
&
strlen
,
&
r
[
0
],
len
)
!=
OK
,
String
());
w64
[
strlen
]
=
0
;
String
ret
=
(
char
*
)
&
w64
[
0
];
return
ret
;
return
ret
;
};
};
...
@@ -2504,19 +2485,8 @@ PoolVector<uint8_t> _Marshalls::base64_to_raw(const String &p_str) {
...
@@ -2504,19 +2485,8 @@ PoolVector<uint8_t> _Marshalls::base64_to_raw(const String &p_str) {
String
_Marshalls
::
utf8_to_base64
(
const
String
&
p_str
)
{
String
_Marshalls
::
utf8_to_base64
(
const
String
&
p_str
)
{
CharString
cstr
=
p_str
.
utf8
();
CharString
cstr
=
p_str
.
utf8
();
int
len
=
cstr
.
length
();
String
ret
=
CryptoCore
::
b64_encode_str
((
unsigned
char
*
)
cstr
.
get_data
(),
cstr
.
length
());
ERR_FAIL_COND_V
(
ret
==
""
,
ret
);
int
b64len
=
len
/
3
*
4
+
4
+
1
;
PoolVector
<
uint8_t
>
b64buff
;
b64buff
.
resize
(
b64len
);
PoolVector
<
uint8_t
>::
Write
w64
=
b64buff
.
write
();
size_t
strlen
=
0
;
ERR_FAIL_COND_V
(
CryptoCore
::
b64_encode
(
&
w64
[
0
],
b64len
,
&
strlen
,
(
unsigned
char
*
)
cstr
.
get_data
(),
len
)
!=
OK
,
String
());
w64
[
strlen
]
=
0
;
String
ret
=
(
char
*
)
&
w64
[
0
];
return
ret
;
return
ret
;
};
};
...
...
core/math/crypto_core.cpp
View file @
24c52f1c
...
@@ -120,6 +120,17 @@ Error CryptoCore::AESContext::decrypt_ecb(const uint8_t p_src[16], uint8_t r_dst
...
@@ -120,6 +120,17 @@ Error CryptoCore::AESContext::decrypt_ecb(const uint8_t p_src[16], uint8_t r_dst
}
}
// CryptoCore
// CryptoCore
String
CryptoCore
::
b64_encode_str
(
const
uint8_t
*
p_src
,
int
p_src_len
)
{
int
b64len
=
p_src_len
/
3
*
4
+
4
+
1
;
PoolVector
<
uint8_t
>
b64buff
;
b64buff
.
resize
(
b64len
);
PoolVector
<
uint8_t
>::
Write
w64
=
b64buff
.
write
();
size_t
strlen
=
0
;
int
ret
=
b64_encode
(
&
w64
[
0
],
b64len
,
&
strlen
,
p_src
,
p_src_len
);
w64
[
strlen
]
=
0
;
return
ret
?
String
()
:
(
const
char
*
)
&
w64
[
0
];
}
Error
CryptoCore
::
b64_encode
(
uint8_t
*
r_dst
,
int
p_dst_len
,
size_t
*
r_len
,
const
uint8_t
*
p_src
,
int
p_src_len
)
{
Error
CryptoCore
::
b64_encode
(
uint8_t
*
r_dst
,
int
p_dst_len
,
size_t
*
r_len
,
const
uint8_t
*
p_src
,
int
p_src_len
)
{
int
ret
=
mbedtls_base64_encode
(
r_dst
,
p_dst_len
,
r_len
,
p_src
,
p_src_len
);
int
ret
=
mbedtls_base64_encode
(
r_dst
,
p_dst_len
,
r_len
,
p_src
,
p_src_len
);
return
ret
?
FAILED
:
OK
;
return
ret
?
FAILED
:
OK
;
...
...
core/math/crypto_core.h
View file @
24c52f1c
...
@@ -79,6 +79,7 @@ public:
...
@@ -79,6 +79,7 @@ public:
Error
decrypt_ecb
(
const
uint8_t
p_src
[
16
],
uint8_t
r_dst
[
16
]);
Error
decrypt_ecb
(
const
uint8_t
p_src
[
16
],
uint8_t
r_dst
[
16
]);
};
};
static
String
b64_encode_str
(
const
uint8_t
*
p_src
,
int
p_src_len
);
static
Error
b64_encode
(
uint8_t
*
r_dst
,
int
p_dst_len
,
size_t
*
r_len
,
const
uint8_t
*
p_src
,
int
p_src_len
);
static
Error
b64_encode
(
uint8_t
*
r_dst
,
int
p_dst_len
,
size_t
*
r_len
,
const
uint8_t
*
p_src
,
int
p_src_len
);
static
Error
b64_decode
(
uint8_t
*
r_dst
,
int
p_dst_len
,
size_t
*
r_len
,
const
uint8_t
*
p_src
,
int
p_src_len
);
static
Error
b64_decode
(
uint8_t
*
r_dst
,
int
p_dst_len
,
size_t
*
r_len
,
const
uint8_t
*
p_src
,
int
p_src_len
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment