This repository was archived by the owner on Oct 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathnetsnmp_ext.c
More file actions
46 lines (35 loc) · 1.3 KB
/
netsnmp_ext.c
File metadata and controls
46 lines (35 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <ruby.h>
#define USM_LENGTH_EXPANDED_PASSPHRASE (1024 * 1024) /* 1Meg. */
#define USM_LENGTH_KU_HASHBLOCK 64
static VALUE mNETSNMP;
static VALUE cNETSNMP_Sec_Params;
static VALUE NETSNMP_expand_passphrase(VALUE self, VALUE password)
{
char *P;
size_t P_len;
int nbytes = USM_LENGTH_EXPANDED_PASSPHRASE;
u_int pindex = 0;
u_char buf[USM_LENGTH_EXPANDED_PASSPHRASE], *bufp;
StringValue(password);
P = RSTRING_PTR(password);
P_len = RSTRING_LEN(password);
bufp = buf;
while (nbytes > 0) {
*bufp++ = P[pindex++ % P_len];
// if (!EVP_DigestUpdate(ctx, buf, USM_LENGTH_KU_HASHBLOCK))
// ossl_raise(eDigestError, "EVP_DigestUpdate");
nbytes--;
}
// if (!EVP_DigestFinal_ex(ctx, &Ku, &kulen))
// ossl_raise(eDigestError, "EVP_DigestFinal_ex");
// memset(buf, 0, sizeof(buf));
// TODO: trim to 16 bytes if auth protocol is md5
return rb_usascii_str_new((const char *) buf, USM_LENGTH_EXPANDED_PASSPHRASE);
}
void Init_netsnmp_ext( void )
{
mNETSNMP = rb_define_module("NETSNMP");
cNETSNMP_Sec_Params = rb_define_class_under(mNETSNMP, "SecurityParameters", rb_cObject);
// rb_define_method(cNETSNMP_Sec_Params, "passkey", NETSNMP_passkey, 1);
rb_define_method(cNETSNMP_Sec_Params, "expand_passphrase", NETSNMP_expand_passphrase, 1);
}