Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Synchronet
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
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
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
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Main
Synchronet
Commits
2883fa6d
Commit
2883fa6d
authored
22 years ago
by
rswindell
Browse files
Options
Downloads
Patches
Plain Diff
Created md5_calc method - returns base64 or hex-encoded MD5 digest of
specified string.
parent
f90f02cf
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/sbbs3/js_global.c
+37
-1
37 additions, 1 deletion
src/sbbs3/js_global.c
with
37 additions
and
1 deletion
src/sbbs3/js_global.c
+
37
−
1
View file @
2883fa6d
...
...
@@ -36,6 +36,7 @@
****************************************************************************/
#include
"sbbs.h"
#include
"md5.h"
#include
"base64.h"
#ifdef JAVASCRIPT
...
...
@@ -948,6 +949,38 @@ js_b64_decode(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval
return
(
JS_TRUE
);
}
static
JSBool
js_md5_calc
(
JSContext
*
cx
,
JSObject
*
obj
,
uintN
argc
,
jsval
*
argv
,
jsval
*
rval
)
{
BYTE
digest
[
MD5_DIGEST_SIZE
];
JSBool
hex
=
JS_FALSE
;
char
*
inbuf
;
char
outbuf
[
64
];
JSString
*
js_str
;
*
rval
=
JSVAL_NULL
;
if
((
inbuf
=
JS_GetStringBytes
(
JS_ValueToString
(
cx
,
argv
[
0
])))
==
NULL
)
return
(
JS_FALSE
);
if
(
argc
>
1
&&
JSVAL_IS_BOOLEAN
(
argv
[
1
]))
hex
=
JSVAL_TO_BOOLEAN
(
argv
[
1
]);
MD5_calc
(
digest
,
inbuf
,
strlen
(
inbuf
));
if
(
hex
)
MD5_hex
(
outbuf
,
digest
);
else
b64_encode
(
outbuf
,
sizeof
(
outbuf
),
digest
,
sizeof
(
digest
));
js_str
=
JS_NewStringCopyZ
(
cx
,
outbuf
);
if
(
js_str
==
NULL
)
return
(
JS_FALSE
);
*
rval
=
STRING_TO_JSVAL
(
js_str
);
return
(
JS_TRUE
);
}
static
JSBool
js_truncsp
(
JSContext
*
cx
,
JSObject
*
obj
,
uintN
argc
,
jsval
*
argv
,
jsval
*
rval
)
{
...
...
@@ -1250,7 +1283,7 @@ static jsMethodSpec js_global_functions[] = {
,
JSDOCSTR
(
"calculate and return 32-bit CRC of string"
)
},
{
"chksum"
,
js_chksum
,
1
,
JSTYPE_NUMBER
,
JSDOCSTR
(
"string text"
)
,
JSDOCSTR
(
"calculate and return 32-bit chksum of string"
)
,
JSDOCSTR
(
"calculate and return 32-bit ch
ec
ksum of string"
)
},
{
"ctrl"
,
js_ctrl
,
1
,
JSTYPE_STRING
,
JSDOCSTR
(
"number or string"
)
,
JSDOCSTR
(
"return ASCII control character representing character passed - Example: <tt>ctrl('C') returns '
\3
'</tt>"
)
...
...
@@ -1329,6 +1362,9 @@ static jsMethodSpec js_global_functions[] = {
{
"base64_decode"
,
js_b64_decode
,
1
,
JSTYPE_STRING
,
JSDOCSTR
(
"string text"
)
,
JSDOCSTR
(
"returns base64-decoded string or <i>null</i> on error"
)
},
{
"md5_calc"
,
js_md5_calc
,
1
,
JSTYPE_STRING
,
JSDOCSTR
(
"string text [,bool hex]"
)
,
JSDOCSTR
(
"returns MD5 digest of string in base64 (default) or hexadecimal encoding"
)
},
{
0
}
};
...
...
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