gwenhywfar/src/impl/msgengine/hbcicryptocontext.c @ c7b52c58
6e3c1d65 | aquamaniac | /***************************************************************************
|
|
$RCSfile$
|
|||
-------------------
|
|||
cvs : $Id$
|
|||
begin : Sat Nov 08 2003
|
|||
copyright : (C) 2003 by Martin Preuss
|
|||
email : martin@libchipcard.de
|
|||
***************************************************************************
|
|||
* *
|
|||
* This library is free software; you can redistribute it and/or *
|
|||
* modify it under the terms of the GNU Lesser General Public *
|
|||
* License as published by the Free Software Foundation; either *
|
|||
* version 2.1 of the License, or (at your option) any later version. *
|
|||
* *
|
|||
* This library is distributed in the hope that it will be useful, *
|
|||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
|
|||
* Lesser General Public License for more details. *
|
|||
* *
|
|||
* You should have received a copy of the GNU Lesser General Public *
|
|||
* License along with this library; if not, write to the Free Software *
|
|||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, *
|
|||
* MA 02111-1307 USA *
|
|||
* *
|
|||
***************************************************************************/
|
|||
#ifdef HAVE_CONFIG_H
|
|||
# include <config.h>
|
|||
#endif
|
|||
#include "hbcicryptocontext_p.h"
|
|||
#include <gwenhyfwar/misc.h>
|
|||
#include <gwenhyfwar/debug.h>
|
|||
/* --------------------------------------------------------------- FUNCTION */
|
|||
const char*
|
|||
GWEN_HBCICryptoContext_GetSecurityIdPtr(GWEN_HBCICRYPTOCONTEXT *ctx){
|
|||
assert(ctx);
|
|||
return ctx->pSecurityId;
|
|||
}
|
|||
/* --------------------------------------------------------------- FUNCTION */
|
|||
void GWEN_HBCICryptoContext_SetSecurityId(GWEN_HBCICRYPTOCONTEXT *ctx,
|
|||
3ead8f55 | aquamaniac | const void *p, unsigned int l){
|
|
6e3c1d65 | aquamaniac | assert(ctx);
|
|
if (ctx->pSecurityId)
|
|||
free(ctx->pSecurityId);
|
|||
ctx->pSecurityId=0;
|
|||
if (l) {
|
|||
ctx->pSecurityId=(char*)malloc(l);
|
|||
ctx->lSecurityId=l;
|
|||
memmove(ctx->pSecurityId, p, l);
|
|||
}
|
|||
}
|
|||
/* --------------------------------------------------------------- FUNCTION */
|
|||
unsigned int
|
|||
GWEN_HBCICryptoContext_GetSecurityIdSize(GWEN_HBCICRYPTOCONTEXT *ctx){
|
|||
assert(ctx);
|
|||
return ctx->lSecurityId;
|
|||
}
|
|||
/* --------------------------------------------------------------- FUNCTION */
|
|||
unsigned int
|
|||
GWEN_HBCICryptoContext_GetSequenceNum(GWEN_HBCICRYPTOCONTEXT *ctx){
|
|||
assert(ctx);
|
|||
return ctx->seq;
|
|||
}
|
|||
/* --------------------------------------------------------------- FUNCTION */
|
|||
void GWEN_HBCICryptoContext_SetSequenceNum(GWEN_HBCICRYPTOCONTEXT *ctx,
|
|||
unsigned int i){
|
|||
assert(ctx);
|
|||
ctx->seq=i;
|
|||
}
|
|||
/* --------------------------------------------------------------- FUNCTION */
|
|||
50e5b742 | aquamaniac | const GWEN_KEYSPEC *
|
|
GWEN_HBCICryptoContext_GetKeySpec(GWEN_HBCICRYPTOCONTEXT *ctx){
|
|||
6e3c1d65 | aquamaniac | assert(ctx);
|
|
return ctx->key;
|
|||
}
|
|||
/* --------------------------------------------------------------- FUNCTION */
|
|||
void GWEN_HBCICryptoContext_SetKeySpec(GWEN_HBCICRYPTOCONTEXT *ctx,
|
|||
5238ce3d | aquamaniac | const GWEN_KEYSPEC *ks){
|
|
6e3c1d65 | aquamaniac | assert(ctx);
|
|
d0476f06 | aquamaniac | assert(ks);
|
|
6e3c1d65 | aquamaniac | if (ctx->key)
|
|
GWEN_KeySpec_free(ctx->key);
|
|||
ctx->key=GWEN_KeySpec_dup(ks);
|
|||
}
|
|||
/* --------------------------------------------------------------- FUNCTION */
|
|||
const char*
|
|||
GWEN_HBCICryptoContext_GetServiceCode(GWEN_HBCICRYPTOCONTEXT *ctx){
|
|||
assert(ctx);
|
|||
return ctx->serviceCode;
|
|||
}
|
|||
/* --------------------------------------------------------------- FUNCTION */
|
|||
void GWEN_HBCICryptoContext_SetServiceCode(GWEN_HBCICRYPTOCONTEXT *ctx,
|
|||
const char *s){
|
|||
assert(ctx);
|
|||
assert(s);
|
|||
free(ctx->serviceCode);
|
|||
ctx->serviceCode=strdup(s);
|
|||
}
|
|||
/* --------------------------------------------------------------- FUNCTION */
|
|||
GWEN_HBCICRYPTOCONTEXT *GWEN_HBCICryptoContext_new(){
|
|||
GWEN_HBCICRYPTOCONTEXT *ctx;
|
|||
GWEN_NEW_OBJECT(GWEN_HBCICRYPTOCONTEXT, ctx);
|
|||
1e7b46b0 | aquamaniac | return ctx;
|
|
6e3c1d65 | aquamaniac | }
|
|
/* --------------------------------------------------------------- FUNCTION */
|
|||
void GWEN_HBCICryptoContext_free(GWEN_HBCICRYPTOCONTEXT *ctx){
|
|||
if (ctx) {
|
|||
free(ctx->pSecurityId);
|
|||
1e7b46b0 | aquamaniac | free(ctx->pCryptKey);
|
|
50e5b742 | aquamaniac | free(ctx->mode);
|
|
free(ctx->serviceCode);
|
|||
6e3c1d65 | aquamaniac | GWEN_KeySpec_free(ctx->key);
|
|
free(ctx);
|
|||
}
|
|||
}
|
|||
1e7b46b0 | aquamaniac | /* --------------------------------------------------------------- FUNCTION */
|
|
void GWEN_HBCICryptoContext_SetCryptKey(GWEN_HBCICRYPTOCONTEXT *ctx,
|
|||
const char *p,
|
|||
unsigned int l){
|
|||
assert(ctx);
|
|||
if (ctx->pCryptKey)
|
|||
free(ctx->pCryptKey);
|
|||
ctx->pCryptKey=0;
|
|||
if (l) {
|
|||
ctx->pCryptKey=(char*)malloc(l);
|
|||
ctx->lCryptKey=l;
|
|||
memmove(ctx->pCryptKey, p, l);
|
|||
}
|
|||
}
|
|||
/* --------------------------------------------------------------- FUNCTION */
|
|||
const char *
|
|||
GWEN_HBCICryptoContext_GetCryptKeyPtr(GWEN_HBCICRYPTOCONTEXT *ctx){
|
|||
assert(ctx);
|
|||
return ctx->pCryptKey;
|
|||
}
|
|||
/* --------------------------------------------------------------- FUNCTION */
|
|||
unsigned int
|
|||
GWEN_HBCICryptoContext_GetCryptKeySize(GWEN_HBCICRYPTOCONTEXT *ctx){
|
|||
assert(ctx);
|
|||
return ctx->lCryptKey;
|
|||
}
|
|||
6e3c1d65 | aquamaniac | ||
5238ce3d | aquamaniac | /* --------------------------------------------------------------- FUNCTION */
|
|
const char *GWEN_HBCICryptoContext_GetMode(GWEN_HBCICRYPTOCONTEXT *ctx){
|
|||
assert(ctx);
|
|||
return ctx->mode;
|
|||
}
|
|||
/* --------------------------------------------------------------- FUNCTION */
|
|||
void GWEN_HBCICryptoContext_SetMode(GWEN_HBCICRYPTOCONTEXT *ctx,
|
|||
const char *m){
|
|||
assert(ctx);
|
|||
assert(m);
|
|||
free(ctx->mode);
|
|||
ctx->mode=strdup(m);
|
|||
}
|
|||
6e3c1d65 | aquamaniac | ||