libcryptx-perl/inc/CryptX_Checksum_Adler32.xs.inc

120 lines
2.9 KiB
PHP
Raw Permalink Normal View History

2018-03-22 15:51:09 +01:00
MODULE = CryptX PACKAGE = Crypt::Checksum::Adler32
2018-03-22 15:54:03 +01:00
PROTOTYPES: DISABLE
2018-03-22 15:51:09 +01:00
Crypt::Checksum::Adler32
new(Class)
CODE:
2018-03-22 15:54:03 +01:00
{
2018-03-22 15:51:09 +01:00
Newz(0, RETVAL, 1, adler32_state);
if (!RETVAL) croak("FATAL: Newz failed");
2018-03-22 15:54:03 +01:00
adler32_init(RETVAL); /* returns void */
}
2018-03-22 15:51:09 +01:00
OUTPUT:
RETVAL
void
DESTROY(Crypt::Checksum::Adler32 self)
CODE:
Safefree(self);
void
reset(Crypt::Checksum::Adler32 self)
2018-03-22 15:54:03 +01:00
PPCODE:
{
adler32_init(self); /* returns void */
XPUSHs(ST(0)); /* return self */
}
2018-03-22 15:51:09 +01:00
Crypt::Checksum::Adler32
clone(Crypt::Checksum::Adler32 self)
CODE:
Newz(0, RETVAL, 1, adler32_state);
if (!RETVAL) croak("FATAL: Newz failed");
Copy(self, RETVAL, 1, adler32_state);
OUTPUT:
RETVAL
void
add(Crypt::Checksum::Adler32 self, ...)
PPCODE:
{
STRLEN inlen;
int i;
unsigned char *in;
for(i=1; i<items; i++) {
in = (unsigned char *)SvPVbyte(ST(i), inlen);
2018-03-22 15:54:03 +01:00
if (inlen > 0) {
adler32_update(self, in, (unsigned long)inlen); /* returns void */
}
2018-03-22 15:51:09 +01:00
}
XPUSHs(ST(0)); /* return self */
}
SV *
digest(Crypt::Checksum::Adler32 self)
2018-03-22 15:54:03 +01:00
ALIAS:
hexdigest = 1
intdigest = 2
2018-03-22 15:51:09 +01:00
CODE:
{
2018-03-22 15:54:03 +01:00
int rv;
unsigned char hash[4], out[8];
unsigned long outlen = 8;
unsigned int ui32;
adler32_finish(self, hash, 4); /* returns void */
if (ix == 1) {
rv = _base16_encode(hash, 4, out, &outlen);
if (rv != CRYPT_OK) croak("FATAL: base16_encode failed: %s", error_to_string(rv));
RETVAL = newSVpvn((char *)out, outlen);
}
else if (ix == 2) {
LOAD32H(ui32, hash);
RETVAL = newSVuv(ui32);
}
else {
RETVAL = newSVpvn((char *) hash, 4);
}
2018-03-22 15:51:09 +01:00
}
OUTPUT:
RETVAL
SV *
2018-03-22 15:54:03 +01:00
adler32_data(...)
ALIAS:
adler32_data_hex = 1
adler32_data_int = 2
2018-03-22 15:51:09 +01:00
CODE:
{
2018-03-22 15:54:03 +01:00
adler32_state st;
int rv, j;
unsigned char hash[4], out[8], *in;
unsigned long outlen = 8;
unsigned int ui32;
STRLEN inlen;
adler32_init(&st);
for(j = 0; j < items; j++) {
in = (unsigned char *)SvPVbyte(ST(j), inlen);
if (inlen > 0) {
adler32_update(&st, in, (unsigned long)inlen); /* returns void */
}
}
adler32_finish(&st, hash, 4); /* returns void */
if (ix == 1) {
rv = _base16_encode(hash, 4, out, &outlen);
if (rv != CRYPT_OK) croak("FATAL: base16_encode failed: %s", error_to_string(rv));
RETVAL = newSVpvn((char *)out, outlen);
}
else if (ix == 2) {
LOAD32H(ui32, hash);
RETVAL = newSVuv(ui32);
}
else {
RETVAL = newSVpvn((char *) hash, 4);
}
2018-03-22 15:51:09 +01:00
}
OUTPUT:
RETVAL