⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 perlcryptlib.xs

📁 cryptlib安全工具包
💻 XS
📖 第 1 页 / 共 2 页
字号:
/******************************************************************************* Perl extesione interface (XS) to 'cryptlib' library (PerlCryptLib) Copyright (C) 2006-2007 Alvaro Livraghi. All Rights Reserved. Alvaro Livraghi, <perlcryptlib@gmail.com>*******************************************************************************/#include "EXTERN.h"#include "perl.h"#include "XSUB.h"#include <stdlib.h>#include "ppport.h"#include CRYPTLIB_H#include "const-c.inc"MODULE = PerlCryptLib		PACKAGE = PerlCryptLib		INCLUDE: const-xs.inc#################################################################################                                                                              ## Funzioni di utilita' generale                                                ##                                                                              ################################################################################### Simula (per Perl) la seguente operazione su un generico buffer:##      void * buffer = "Questo e' un buffer";#      buffer += offset;#void * shift_buffer(buffer, length, offset)	void * buffer;	int length;	const int offset;	INIT:		void * __buffer;	CODE:		if ( __buffer = (void *)malloc(length) ) {			length -= offset;			buffer += offset;			memcpy(__buffer, buffer, length);			sv_setpvn(ST(0), __buffer, length);			RETVAL = newSVpvn(__buffer, length);			free(__buffer);		}	OUTPUT:		length#################################################################################                                                                              ## Trascodifica funzioni di cryptlib                                            ##                                                                              #################################################################################int cryptInit()int cryptEnd()int cryptLogin(user, name, password)	int user;	const char * name;	const char * password;	CODE:		RETVAL = cryptLogin(&user, name, password);	OUTPUT:		RETVAL		userint cryptLogout(user)	const int user;int cryptCreateEnvelope(cryptEnvelope, cryptUser, formatType)	int cryptEnvelope;	const int cryptUser;	const int formatType;	CODE:		RETVAL = cryptCreateEnvelope(&cryptEnvelope, cryptUser, formatType);	OUTPUT:		RETVAL		cryptEnvelopeint cryptDestroyEnvelope(cryptEnvelope)	const int cryptEnvelope;int cryptSetAttribute(cryptEnvelope, attributeType, value)	const int cryptEnvelope;	const int attributeType;	const int value;int cryptSetAttributeString(cryptEnvelope, attributeType, value, valueLength)	const int cryptEnvelope;	const int attributeType;	const void * value;	const int valueLength;int cryptGetAttribute(cryptObject, attributeType, value)	const int cryptObject;	const int attributeType;	int value;	CODE:		RETVAL = cryptGetAttribute(cryptObject, attributeType, &value);	OUTPUT:		RETVAL		valueint cryptGetAttributeString(cryptObject, attributeType, value, valueLength)	const int cryptObject;	const int attributeType;	void * value = (SvIOK(ST(2)) ? (void *)SvIV(ST(2)) : (void *)SvPV_nolen(ST(2)));	int valueLength;	CODE:		RETVAL = cryptGetAttributeString(cryptObject, attributeType, value, &valueLength);		if ( RETVAL == CRYPT_OK ) sv_setpvn(ST(2), value, valueLength);	OUTPUT:		RETVAL		valueLengthint cryptPushData(cryptEnvelope, buffer, length, bytesCopied)	const int cryptEnvelope;	const void * buffer = (SvIOK(ST(1)) ? (const void *)SvIV(ST(1)) : (const void *)SvPV_nolen(ST(1)));	const int length;	int bytesCopied;	CODE:		RETVAL = cryptPushData(cryptEnvelope, buffer, length, &bytesCopied);	OUTPUT:		RETVAL		bytesCopiedint cryptFlushData(cryptEnvelope)	const int cryptEnvelope;int cryptPopData(cryptEnvelope, buffer, length, bytesCopied)	const int cryptEnvelope;	void * buffer;	const int length;	int bytesCopied;	CODE:		RETVAL = cryptPopData(cryptEnvelope, buffer, length, &bytesCopied);		if ( RETVAL == CRYPT_OK ) sv_setpvn(ST(1), buffer, bytesCopied);	OUTPUT:		RETVAL		bytesCopiedint cryptCreateContext(cryptContext, cryptUser, cryptAlgo)	int cryptContext;	const int cryptUser;	const int cryptAlgo;	CODE:		RETVAL = cryptCreateContext(&cryptContext, cryptUser, cryptAlgo);	OUTPUT:		RETVAL		cryptContextint cryptDestroyContext(cryptContext)	const int cryptContext;int cryptKeysetOpen(keyset, cryptUser, keysetType, name, options)	int keyset;	const int cryptUser;	const int keysetType;	const char * name;	const int options;	CODE:		RETVAL = cryptKeysetOpen(&keyset, cryptUser, keysetType, name, options);	OUTPUT:		RETVAL		keysetint cryptKeysetClose(keyset)	const int keysetint cryptGenerateKey(cryptContext)	const int cryptContextint cryptExportKey(encryptedKey, encryptedKeyMaxLength, encryptedKeyLength, exportKey, sessionKeyContext)	void * encryptedKey = (SvIOK(ST(0)) ? (void *)SvIV(ST(0)) : (void *)SvPV_nolen(ST(0)));	const int encryptedKeyMaxLength;	int encryptedKeyLength;	const int exportKey;	const int sessionKeyContext;	CODE:		RETVAL = cryptExportKey(encryptedKey, encryptedKeyMaxLength, &encryptedKeyLength, exportKey, sessionKeyContext);		if ( RETVAL == CRYPT_OK ) sv_setpvn(ST(0), encryptedKey, encryptedKeyLength);	OUTPUT:		RETVAL		encryptedKeyLengthint cryptCreateCert(cryptCert, cryptUser, certType)	int cryptCert;	const int cryptUser;	const int certType;	CODE:		RETVAL = cryptCreateCert(&cryptCert, cryptUser, certType);	OUTPUT:		RETVAL		cryptCertint cryptSignCert(certificate, signContext)	const int certificate;	const int signContext;int cryptImportCert(certObject, certObjectLength, cryptUser, certificate)	const void * certObject;	const int certObjectLength;	const int cryptUser;	int certificate;	CODE:		RETVAL = cryptImportCert(certObject, certObjectLength, cryptUser, &certificate);	OUTPUT:		RETVAL		certificateint cryptExportCert(certObject, certObjectMaxLength, certObjectLength, certFormatType, certificate)	void * certObject = (SvIOK(ST(0)) ? (void *)SvIV(ST(0)) : (void *)SvPV_nolen(ST(0)));	const int certObjectMaxLength;	int certObjectLength;	const int certFormatType;	const int certificate;	CODE:		RETVAL = cryptExportCert(certObject, certObjectMaxLength, &certObjectLength, certFormatType, certificate);		if ( RETVAL == CRYPT_OK ) sv_setpvn(ST(0), certObject, certObjectLength);	OUTPUT:		RETVAL		certObjectLengthint cryptCheckCert(certRequest, cryptCA)	const int certRequest;	const int cryptCA;int cryptDestroyCert(cryptCert)	const int cryptCert;int cryptImportKey(encryptedKey, encryptedKeyLength, importContext, sessionKeyContext)	const void * encryptedKey;	const int encryptedKeyLength;	const int importContext;	const int sessionKeyContext;int cryptImportKeyEx(encryptedKey, encryptedKeyLength, importContext, sessionKeyContext, returnedContext)	const void * encryptedKey;	const int encryptedKeyLength;	const int importContext;	const int sessionKeyContext;	int returnedContext;	CODE:		RETVAL = cryptImportKeyEx(encryptedKey, encryptedKeyLength, importContext, sessionKeyContext, &returnedContext);	OUTPUT:		RETVAL		returnedContextint cryptAddPublicKey(keyset, certificate)	const int keyset;	const int certificate;int cryptAddPrivateKey(keyset, cryptKey, password)	const int keyset;	const int cryptKey;	const char * password;int cryptGetPrivateKey(cryptHandle, cryptContext, keyIDtype, keyID, password)	const int cryptHandle;	int cryptContext;	const int keyIDtype;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -