Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
Nodemcu Firmware
Commits
96f905bf
Commit
96f905bf
authored
Feb 13, 2016
by
Adam Bonner
Browse files
Crypto-new_hash Improved code based on review in #1037
parent
332b53b9
Changes
1
Hide whitespace changes
Inline
Side-by-side
app/modules/crypto.c
View file @
96f905bf
...
@@ -148,6 +148,9 @@ static int crypto_new_hash (lua_State *L)
...
@@ -148,6 +148,9 @@ static int crypto_new_hash (lua_State *L)
return
bad_mech
(
L
);
return
bad_mech
(
L
);
void
*
ctx
=
os_malloc
(
mi
->
ctx_size
);
void
*
ctx
=
os_malloc
(
mi
->
ctx_size
);
if
(
ctx
==
NULL
)
return
bad_mem
(
L
);
mi
->
create
(
ctx
);
mi
->
create
(
ctx
);
// create a userdataum with specific metatable
// create a userdataum with specific metatable
...
@@ -173,16 +176,9 @@ static int crypto_hash_update (lua_State *L)
...
@@ -173,16 +176,9 @@ static int crypto_hash_update (lua_State *L)
dudat
=
(
digest_user_datum_t
*
)
luaL_checkudata
(
L
,
1
,
"crypto.hash"
);
dudat
=
(
digest_user_datum_t
*
)
luaL_checkudata
(
L
,
1
,
"crypto.hash"
);
luaL_argcheck
(
L
,
dudat
,
1
,
"crypto.hash expected"
);
luaL_argcheck
(
L
,
dudat
,
1
,
"crypto.hash expected"
);
if
(
dudat
==
NULL
){
NODE_DBG
(
"userdata is nil.
\n
"
);
return
0
;
}
const
digest_mech_info_t
*
mi
=
dudat
->
mech_info
;
const
digest_mech_info_t
*
mi
=
dudat
->
mech_info
;
if
(
!
mi
)
return
bad_mech
(
L
);
size_t
len
=
0
;
size_t
len
=
0
;
const
char
*
data
=
luaL_checklstring
(
L
,
2
,
&
len
);
const
char
*
data
=
luaL_checklstring
(
L
,
2
,
&
len
);
...
@@ -200,10 +196,6 @@ static int crypto_hash_finalize (lua_State *L)
...
@@ -200,10 +196,6 @@ static int crypto_hash_finalize (lua_State *L)
dudat
=
(
digest_user_datum_t
*
)
luaL_checkudata
(
L
,
1
,
"crypto.hash"
);
dudat
=
(
digest_user_datum_t
*
)
luaL_checkudata
(
L
,
1
,
"crypto.hash"
);
luaL_argcheck
(
L
,
dudat
,
1
,
"crypto.hash expected"
);
luaL_argcheck
(
L
,
dudat
,
1
,
"crypto.hash expected"
);
if
(
dudat
==
NULL
){
NODE_DBG
(
"userdata is nil.
\n
"
);
return
0
;
}
const
digest_mech_info_t
*
mi
=
dudat
->
mech_info
;
const
digest_mech_info_t
*
mi
=
dudat
->
mech_info
;
...
@@ -219,14 +211,9 @@ static int crypto_hash_gcdelete (lua_State *L)
...
@@ -219,14 +211,9 @@ static int crypto_hash_gcdelete (lua_State *L)
{
{
NODE_DBG
(
"enter crypto_hash_delete.
\n
"
);
NODE_DBG
(
"enter crypto_hash_delete.
\n
"
);
digest_user_datum_t
*
dudat
;
digest_user_datum_t
*
dudat
;
size_t
sl
;
dudat
=
(
digest_user_datum_t
*
)
luaL_checkudata
(
L
,
1
,
"crypto.hash"
);
dudat
=
(
digest_user_datum_t
*
)
luaL_checkudata
(
L
,
1
,
"crypto.hash"
);
luaL_argcheck
(
L
,
dudat
,
1
,
"crypto.hash expected"
);
luaL_argcheck
(
L
,
dudat
,
1
,
"crypto.hash expected"
);
if
(
dudat
==
NULL
){
NODE_DBG
(
"userdata is nil.
\n
"
);
return
0
;
}
os_free
(
dudat
->
ctx
);
os_free
(
dudat
->
ctx
);
os_free
(
dudat
);
os_free
(
dudat
);
...
...
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