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
6c512e21
Commit
6c512e21
authored
Jul 02, 2019
by
Fabio Alessandrelli
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add sha1 functions to string (using new CryptoCore)
parent
a3bdb6c8
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
0 deletions
+27
-0
ustring.cpp
core/ustring.cpp
+21
-0
ustring.h
core/ustring.h
+2
-0
variant_call.cpp
core/variant_call.cpp
+4
-0
No files found.
core/ustring.cpp
View file @
6c512e21
...
...
@@ -2257,6 +2257,13 @@ String String::md5_text() const {
return
String
::
hex_encode_buffer
(
hash
,
16
);
}
String
String
::
sha1_text
()
const
{
CharString
cs
=
utf8
();
unsigned
char
hash
[
20
];
CryptoCore
::
sha1
((
unsigned
char
*
)
cs
.
ptr
(),
cs
.
length
(),
hash
);
return
String
::
hex_encode_buffer
(
hash
,
20
);
}
String
String
::
sha256_text
()
const
{
CharString
cs
=
utf8
();
unsigned
char
hash
[
32
];
...
...
@@ -2278,6 +2285,20 @@ Vector<uint8_t> String::md5_buffer() const {
return
ret
;
};
Vector
<
uint8_t
>
String
::
sha1_buffer
()
const
{
CharString
cs
=
utf8
();
unsigned
char
hash
[
20
];
CryptoCore
::
sha1
((
unsigned
char
*
)
cs
.
ptr
(),
cs
.
length
(),
hash
);
Vector
<
uint8_t
>
ret
;
ret
.
resize
(
20
);
for
(
int
i
=
0
;
i
<
20
;
i
++
)
{
ret
.
write
[
i
]
=
hash
[
i
];
}
return
ret
;
}
Vector
<
uint8_t
>
String
::
sha256_buffer
()
const
{
CharString
cs
=
utf8
();
unsigned
char
hash
[
32
];
...
...
core/ustring.h
View file @
6c512e21
...
...
@@ -305,8 +305,10 @@ public:
uint32_t
hash
()
const
;
/* hash the string */
uint64_t
hash64
()
const
;
/* hash the string */
String
md5_text
()
const
;
String
sha1_text
()
const
;
String
sha256_text
()
const
;
Vector
<
uint8_t
>
md5_buffer
()
const
;
Vector
<
uint8_t
>
sha1_buffer
()
const
;
Vector
<
uint8_t
>
sha256_buffer
()
const
;
_FORCE_INLINE_
bool
empty
()
const
{
return
length
()
==
0
;
}
...
...
core/variant_call.cpp
View file @
6c512e21
...
...
@@ -275,8 +275,10 @@ struct _VariantCall {
VCALL_LOCALMEM2
(
String
,
erase
);
VCALL_LOCALMEM0R
(
String
,
hash
);
VCALL_LOCALMEM0R
(
String
,
md5_text
);
VCALL_LOCALMEM0R
(
String
,
sha1_text
);
VCALL_LOCALMEM0R
(
String
,
sha256_text
);
VCALL_LOCALMEM0R
(
String
,
md5_buffer
);
VCALL_LOCALMEM0R
(
String
,
sha1_buffer
);
VCALL_LOCALMEM0R
(
String
,
sha256_buffer
);
VCALL_LOCALMEM0R
(
String
,
empty
);
VCALL_LOCALMEM0R
(
String
,
is_abs_path
);
...
...
@@ -1539,8 +1541,10 @@ void register_variant_methods() {
ADDFUNC2
(
STRING
,
NIL
,
String
,
erase
,
INT
,
"position"
,
INT
,
"chars"
,
varray
());
ADDFUNC0R
(
STRING
,
INT
,
String
,
hash
,
varray
());
ADDFUNC0R
(
STRING
,
STRING
,
String
,
md5_text
,
varray
());
ADDFUNC0R
(
STRING
,
STRING
,
String
,
sha1_text
,
varray
());
ADDFUNC0R
(
STRING
,
STRING
,
String
,
sha256_text
,
varray
());
ADDFUNC0R
(
STRING
,
POOL_BYTE_ARRAY
,
String
,
md5_buffer
,
varray
());
ADDFUNC0R
(
STRING
,
POOL_BYTE_ARRAY
,
String
,
sha1_buffer
,
varray
());
ADDFUNC0R
(
STRING
,
POOL_BYTE_ARRAY
,
String
,
sha256_buffer
,
varray
());
ADDFUNC0R
(
STRING
,
BOOL
,
String
,
empty
,
varray
());
ADDFUNC0R
(
STRING
,
BOOL
,
String
,
is_abs_path
,
varray
());
...
...
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