Make the perl module compile and eliminate some of the warnings.
[openssl.git] / perl / openssl_digest.xs
1
2 #include "openssl.h"
3
4 int boot_digest()
5         {
6         SSLeay_add_all_digests();
7         return(1);
8         }
9
10 MODULE =  OpenSSL::MD   PACKAGE = OpenSSL::MD   PREFIX = p5_EVP_MD_
11
12 PROTOTYPES: ENABLE
13 VERSIONCHECK: DISABLE
14
15 # OpenSSL::MD::new(name) name= md2, md5, sha, sha1, or mdc2
16 #       md->name() - returns the name
17 #       md->init() - reinitalises the digest
18 #       md->update(data) - adds more data to digest
19 #       digest=md->final() - returns digest
20 #
21
22 void
23 p5_EVP_MD_new(...)
24         PREINIT:
25                 EVP_MD_CTX *ctx;
26                 const EVP_MD *md;
27                 char *name;
28         PPCODE:
29                 if ((items == 1) && SvPOK(ST(0)))
30                         name=SvPV(ST(0),na);
31                 else if ((items == 2) && SvPOK(ST(1)))
32                         name=SvPV(ST(1),na);
33                 else
34                         croak("Usage: OpenSSL::MD::new(type)");
35                 PUSHs(sv_newmortal());
36                 md=EVP_get_digestbyname(name);
37                 if (md != NULL)
38                         {
39                         ctx=malloc(sizeof(EVP_MD_CTX));
40                         EVP_DigestInit(ctx,md);
41                         sv_setref_pv(ST(0), "OpenSSL::MD", (void*)ctx);
42                         }
43
44 datum
45 p5_EVP_MD_name(ctx)
46         EVP_MD_CTX *ctx
47         CODE:
48                 RETVAL.dptr=OBJ_nid2ln(EVP_MD_type(EVP_MD_CTX_type(ctx)));
49                 RETVAL.dsize=strlen(RETVAL.dptr);
50         OUTPUT:
51                 RETVAL
52         
53 void
54 p5_EVP_MD_init(ctx)
55         EVP_MD_CTX *ctx
56         CODE:
57                 EVP_DigestInit(ctx,EVP_MD_CTX_type(ctx));
58
59 void
60 p5_EVP_MD_update(ctx, in)
61         EVP_MD_CTX *ctx
62         datum in
63         CODE:
64                 EVP_DigestUpdate(ctx,in.dptr,in.dsize);
65
66 datum
67 p5_EVP_MD_final(ctx)
68         EVP_MD_CTX *ctx
69         PREINIT:
70                 char md[EVP_MAX_MD_SIZE];
71                 int len;
72         CODE:
73                 EVP_DigestFinal(ctx,md,&len);
74                 RETVAL.dptr=md;
75                 RETVAL.dsize=len;
76         OUTPUT:
77                 RETVAL
78
79 void
80 p5_EVP_MD_DESTROY(ctx)
81         EVP_MD_CTX *ctx
82         CODE:
83         free((char *)ctx);
84