Add language bindings for tcl and perl

This commit is contained in:
agc 2009-12-01 06:43:57 +00:00
parent 6b13238156
commit e1d61885e2
13 changed files with 7621 additions and 0 deletions

View File

@ -0,0 +1,15 @@
# $NetBSD: Makefile,v 1.1 2009/12/01 06:43:57 agc Exp $
# Automatically generated by swigit wrapper script
PREFIX=/usr/pkg
LIB=netpgpperl
SRCS=netpgpperl_wrap.c
WARNS=0
MKMAN=no
CPPFLAGS+=-I${PREFIX}/include
CPPFLAGS+=-I/usr/pkg/lib/perl5/5.10.0/i386-netbsd-thread-multi/CORE
LDFLAGS+=-L${PREFIX}/lib
LDADD+=-lnetpgp
.include <bsd.lib.mk>

View File

@ -0,0 +1,91 @@
/*-
* Copyright (c) 2009 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Alistair Crooks (agc@netbsd.org)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef NETPGP_H_
#define NETPGP_H_
#ifndef __BEGIN_DECLS
# if defined(__cplusplus)
# define __BEGIN_DECLS extern "C" {
# define __END_DECLS }
# else
# define __BEGIN_DECLS
# define __END_DECLS
# endif
#endif
__BEGIN_DECLS
/* structure used to hold (key,value) pair information */
typedef struct netpgp_t {
unsigned c; /* # of elements used */
unsigned size; /* size of array */
char **name; /* key names */
char **value; /* value information */
void *pubring; /* public key ring */
void *secring; /* s3kr1t key ring */
void *io; /* the io struct for results/errs */
void *passfp; /* file pointer for password input */
} netpgp_t;
/* begin and end */
int netpgp_init(netpgp_t *);
int netpgp_end(netpgp_t *);
/* debugging, reflection and information */
int netpgp_set_debug(const char *);
int netpgp_get_debug(const char *);
const char *netpgp_get_info(const char *);
int netpgp_list_packets(netpgp_t *, char *, int, char *);
/* variables */
int netpgp_setvar(netpgp_t *, const char *, const char *);
char *netpgp_getvar(netpgp_t *, const char *);
/* key management */
int netpgp_list_keys(netpgp_t *);
int netpgp_list_sigs(netpgp_t *, const char *);
int netpgp_find_key(netpgp_t *, char *);
char *netpgp_get_key(netpgp_t *, const char *);
int netpgp_export_key(netpgp_t *, char *);
int netpgp_import_key(netpgp_t *, char *);
int netpgp_generate_key(netpgp_t *, char *, int);
/* file management */
int netpgp_encrypt_file(netpgp_t *, const char *, const char *, char *, int);
int netpgp_decrypt_file(netpgp_t *, const char *, char *, int);
int netpgp_sign_file(netpgp_t *, const char *, const char *, char *, int, int, int);
int netpgp_verify_file(netpgp_t *, const char *, const char *, int);
/* memory signing */
int netpgp_sign_memory(netpgp_t *, const char *, char *, size_t, char *, size_t, const unsigned, const unsigned);
int netpgp_verify_memory(netpgp_t *, const void *, const size_t, const int);
__END_DECLS
#endif /* !NETPGP_H_ */

View File

@ -0,0 +1,29 @@
#! /usr/pkg/bin/perl -wT
# netpgp bindings for perl
use lib "/usr/src/crypto/external/bsd/netpgp-bindings/dist/bindings/perl";
use netpgpperl;
# initializations
$n = netpgpperlc::new_netpgp_t();
netpgpperlc::netpgp_setvar($n, "homedir", "/home/agc/.gnupg");
netpgpperlc::netpgp_setvar($n, "hash", "SHA256");
netpgpperlc::netpgp_init($n);
# get the default userid
$userid = netpgpperlc::netpgp_getvar($n, "userid");
foreach $i (0 .. $#ARGV) {
# set up file names
#my $in = $ARGV[$i];
#my $out = $in . ".gpg";
# sign the file, output is in $out
#netpgpperlc::netpgp_sign_file($n, $userid, $in, $out, 0, 0, 0);
netpgpperlc::netpgp_sign_file($n, $userid, "a", "a.gpg", 0, 0, 0);
# verify the signed file $out
netpgpperlc::netpgp_verify_file($n, "a.gpg", "/dev/null", 0);
}

View File

@ -0,0 +1,5 @@
%module netpgpperl
%{
#include <netpgp.h>
%}
%include netpgp.h

View File

@ -0,0 +1,131 @@
# This file was automatically generated by SWIG (http://www.swig.org).
# Version 1.3.31
#
# Don't modify this file, modify the SWIG interface instead.
package netpgpperl;
require Exporter;
require DynaLoader;
@ISA = qw(Exporter DynaLoader);
package netpgpperlc;
bootstrap netpgpperl;
package netpgpperl;
@EXPORT = qw( );
# ---------- BASE METHODS -------------
package netpgpperl;
sub TIEHASH {
my ($classname,$obj) = @_;
return bless $obj, $classname;
}
sub CLEAR { }
sub FIRSTKEY { }
sub NEXTKEY { }
sub FETCH {
my ($self,$field) = @_;
my $member_func = "swig_${field}_get";
$self->$member_func();
}
sub STORE {
my ($self,$field,$newval) = @_;
my $member_func = "swig_${field}_set";
$self->$member_func($newval);
}
sub this {
my $ptr = shift;
return tied(%$ptr);
}
# ------- FUNCTION WRAPPERS --------
package netpgpperl;
*netpgp_init = *netpgpperlc::netpgp_init;
*netpgp_end = *netpgpperlc::netpgp_end;
*netpgp_set_debug = *netpgpperlc::netpgp_set_debug;
*netpgp_get_debug = *netpgpperlc::netpgp_get_debug;
*netpgp_get_info = *netpgpperlc::netpgp_get_info;
*netpgp_list_packets = *netpgpperlc::netpgp_list_packets;
*netpgp_setvar = *netpgpperlc::netpgp_setvar;
*netpgp_getvar = *netpgpperlc::netpgp_getvar;
*netpgp_list_keys = *netpgpperlc::netpgp_list_keys;
*netpgp_list_sigs = *netpgpperlc::netpgp_list_sigs;
*netpgp_find_key = *netpgpperlc::netpgp_find_key;
*netpgp_get_key = *netpgpperlc::netpgp_get_key;
*netpgp_export_key = *netpgpperlc::netpgp_export_key;
*netpgp_import_key = *netpgpperlc::netpgp_import_key;
*netpgp_generate_key = *netpgpperlc::netpgp_generate_key;
*netpgp_encrypt_file = *netpgpperlc::netpgp_encrypt_file;
*netpgp_decrypt_file = *netpgpperlc::netpgp_decrypt_file;
*netpgp_sign_file = *netpgpperlc::netpgp_sign_file;
*netpgp_verify_file = *netpgpperlc::netpgp_verify_file;
*netpgp_sign_memory = *netpgpperlc::netpgp_sign_memory;
*netpgp_verify_memory = *netpgpperlc::netpgp_verify_memory;
############# Class : netpgpperl::netpgp_t ##############
package netpgpperl::netpgp_t;
use vars qw(@ISA %OWNER %ITERATORS %BLESSEDMEMBERS);
@ISA = qw( netpgpperl );
%OWNER = ();
%ITERATORS = ();
*swig_c_get = *netpgpperlc::netpgp_t_c_get;
*swig_c_set = *netpgpperlc::netpgp_t_c_set;
*swig_size_get = *netpgpperlc::netpgp_t_size_get;
*swig_size_set = *netpgpperlc::netpgp_t_size_set;
*swig_name_get = *netpgpperlc::netpgp_t_name_get;
*swig_name_set = *netpgpperlc::netpgp_t_name_set;
*swig_value_get = *netpgpperlc::netpgp_t_value_get;
*swig_value_set = *netpgpperlc::netpgp_t_value_set;
*swig_pubring_get = *netpgpperlc::netpgp_t_pubring_get;
*swig_pubring_set = *netpgpperlc::netpgp_t_pubring_set;
*swig_secring_get = *netpgpperlc::netpgp_t_secring_get;
*swig_secring_set = *netpgpperlc::netpgp_t_secring_set;
*swig_io_get = *netpgpperlc::netpgp_t_io_get;
*swig_io_set = *netpgpperlc::netpgp_t_io_set;
*swig_passfp_get = *netpgpperlc::netpgp_t_passfp_get;
*swig_passfp_set = *netpgpperlc::netpgp_t_passfp_set;
sub new {
my $pkg = shift;
my $self = netpgpperlc::new_netpgp_t(@_);
bless $self, $pkg if defined($self);
}
sub DESTROY {
return unless $_[0]->isa('HASH');
my $self = tied(%{$_[0]});
return unless defined $self;
delete $ITERATORS{$self};
if (exists $OWNER{$self}) {
netpgpperlc::delete_netpgp_t($self);
delete $OWNER{$self};
}
}
sub DISOWN {
my $self = shift;
my $ptr = tied(%$self);
delete $OWNER{$ptr};
}
sub ACQUIRE {
my $self = shift;
my $ptr = tied(%$self);
$OWNER{$ptr} = 1;
}
# ------- VARIABLE STUBS --------
package netpgpperl;
1;

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,22 @@
major=0
minor=0
major=0
minor=0
major=0
minor=0
major=0
minor=0
major=0
minor=0
major=0
minor=0
major=0
minor=0
major=0
minor=0
major=0
minor=0
major=0
minor=0
major=0
minor=0

View File

@ -0,0 +1,15 @@
# $NetBSD: Makefile,v 1.1 2009/12/01 06:43:57 agc Exp $
# Automatically generated by swigit wrapper script
PREFIX=/usr/pkg
LIB=netpgptcl
SRCS=netpgptcl_wrap.c
WARNS=0
MKMAN=no
CPPFLAGS+=-I${PREFIX}/include
LDFLAGS+=-L${PREFIX}/lib
LDADD+=-lnetpgp
.include <bsd.lib.mk>

View File

@ -0,0 +1,91 @@
/*-
* Copyright (c) 2009 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Alistair Crooks (agc@netbsd.org)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef NETPGP_H_
#define NETPGP_H_
#ifndef __BEGIN_DECLS
# if defined(__cplusplus)
# define __BEGIN_DECLS extern "C" {
# define __END_DECLS }
# else
# define __BEGIN_DECLS
# define __END_DECLS
# endif
#endif
__BEGIN_DECLS
/* structure used to hold (key,value) pair information */
typedef struct netpgp_t {
unsigned c; /* # of elements used */
unsigned size; /* size of array */
char **name; /* key names */
char **value; /* value information */
void *pubring; /* public key ring */
void *secring; /* s3kr1t key ring */
void *io; /* the io struct for results/errs */
void *passfp; /* file pointer for password input */
} netpgp_t;
/* begin and end */
int netpgp_init(netpgp_t *);
int netpgp_end(netpgp_t *);
/* debugging, reflection and information */
int netpgp_set_debug(const char *);
int netpgp_get_debug(const char *);
const char *netpgp_get_info(const char *);
int netpgp_list_packets(netpgp_t *, char *, int, char *);
/* variables */
int netpgp_setvar(netpgp_t *, const char *, const char *);
char *netpgp_getvar(netpgp_t *, const char *);
/* key management */
int netpgp_list_keys(netpgp_t *);
int netpgp_list_sigs(netpgp_t *, const char *);
int netpgp_find_key(netpgp_t *, char *);
char *netpgp_get_key(netpgp_t *, const char *);
int netpgp_export_key(netpgp_t *, char *);
int netpgp_import_key(netpgp_t *, char *);
int netpgp_generate_key(netpgp_t *, char *, int);
/* file management */
int netpgp_encrypt_file(netpgp_t *, const char *, const char *, char *, int);
int netpgp_decrypt_file(netpgp_t *, const char *, char *, int);
int netpgp_sign_file(netpgp_t *, const char *, const char *, char *, int, int, int);
int netpgp_verify_file(netpgp_t *, const char *, const char *, int);
/* memory signing */
int netpgp_sign_memory(netpgp_t *, const char *, char *, size_t, char *, size_t, const unsigned, const unsigned);
int netpgp_verify_memory(netpgp_t *, const void *, const size_t, const int);
__END_DECLS
#endif /* !NETPGP_H_ */

View File

@ -0,0 +1,15 @@
#! /usr/bin/env tclsh
# netpgp bindings for tcl
load libnetpgptcl.so
# initialisations
set n [new_netpgp_t]
netpgp_setvar $n "homedir" "/home/agc/.gnupg"
netpgp_setvar $n "hash" "SHA256"
netpgp_init $n
set userid [netpgp_getvar $n "userid"]
netpgp_sign_file $n $userid "a" "a.gpg" 0 0 0
netpgp_verify_file $n "a.gpg" "/dev/null" 0

View File

@ -0,0 +1,5 @@
%module netpgptcl
%{
#include <netpgp.h>
%}
%include netpgp.h

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,20 @@
major=0
minor=0
major=0
minor=0
major=0
minor=0
major=0
minor=0
major=0
minor=0
major=0
minor=0
major=0
minor=0
major=0
minor=0
major=0
minor=0
major=0
minor=0