/***************************************************************************
                            KSSLPKCS12.m -  description
                             -------------------
    begin                : Fri Mar  8 13:55:08 2002
    copyright            : (C) 2000-2002 Lost Highway Ltd. All rights reserved.
    email                : Lost_Highway@tipitina.demon.co.uk
    generated by         : duke@tipitina on Fri Mar  8 13:55:08 2002, using kalyptus 0.9.
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This library is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU Library General Public License as       *
 *   published by the Free Software Foundation; either version 2 of the    *
 *   License, or (at your option) any later version.                       *
 *                                                                         *
 ***************************************************************************/

#include <qtc/qt_QString.h>
#include <qtc/qt_QCString.h>
#include <kdec/kde_KSSLPKCS12.h>
#include <kdeobjc/KDESupport.h>
#include <kdeobjc/KSSLPKCS12.h>

@implementation  KSSLPKCS12

- (void *) qt
{
	return _qt;
}

- setQt: (void *) qt
{
	_qt = qt;
	return self;
}

- (BOOL) allocatedInObjcWorld
{
	return _allocatedInObjcWorld;
}

- setAllocatedInObjcWorld: (BOOL) yn
{
	_allocatedInObjcWorld = yn;
	return self;
}


- (void) dealloc
{
	if ([self qt] != 0L) {
		if ([self allocatedInObjcWorld]) {
			kde_del_KSSLPKCS12((kde_KSSLPKCS12 *)[self qt]);
		}
		[QtSupport removeQtKey: [self qt]];
		[self setQt: 0L];
	}
	[super dealloc];
}

- (NSString *) name
{
static qt_QString * _qstring = 0L;
	_qstring = kde_KSSLPKCS12_name((kde_KSSLPKCS12 *)[self qt]);
	return [NSString fromQString: _qstring];
}

- (NSString *) toString
{
static qt_QString * _qstring = 0L;
	_qstring = kde_KSSLPKCS12_toString((kde_KSSLPKCS12 *)[self qt]);
	return [NSString fromQString: _qstring];
}

//- setCert: (PKCS12*)c
//{
//	kde_KSSLPKCS12_setCert((kde_KSSLPKCS12 *)[self qt], (PKCS12*) c);
//	return self;
//}

- (BOOL) changePassword: (NSString *)pold pnew: (NSString *)pnew
{
static qt_QString * _qstring_pnew = 0L;
static qt_QString * _qstring_pold = 0L;
	return (BOOL) kde_KSSLPKCS12_changePassword((kde_KSSLPKCS12 *)[self qt], (qt_QString *) [pold toQString: &_qstring_pold], (qt_QString *) [pnew toQString: &_qstring_pnew]);
}

//- (EVP_PKEY*) getPrivateKey
//{
//	return (EVP_PKEY*) kde_KSSLPKCS12_getPrivateKey((kde_KSSLPKCS12 *)[self qt]);
//}

- (KSSLCertificate*) getCertificate
{
	return (KSSLCertificate*) [QtSupport objectForQtKey: kde_KSSLPKCS12_getCertificate((kde_KSSLPKCS12 *)[self qt]) withClass: [KSSLCertificate class] allocatedInObjcWorld: YES];
}

- (BOOL) toFile: (NSString *)filename
{
static qt_QString * _qstring_filename = 0L;
	return (BOOL) kde_KSSLPKCS12_toFile((kde_KSSLPKCS12 *)[self qt], (qt_QString *) [filename toQString: &_qstring_filename]);
}

- (int) validate
{
	return (int) kde_KSSLPKCS12_validate((kde_KSSLPKCS12 *)[self qt]);
}

- (int) revalidate
{
	return (int) kde_KSSLPKCS12_revalidate((kde_KSSLPKCS12 *)[self qt]);
}

- (BOOL) isValid
{
	return (BOOL) kde_KSSLPKCS12_isValid((kde_KSSLPKCS12 *)[self qt]);
}

+ (KSSLPKCS12*) fromString: (NSString *)base64 password: (NSString *)password
{
static qt_QString * _qstring_password = 0L;
static qt_QString * _qstring_base64 = 0L;
	return (KSSLPKCS12*) [QtSupport objectForQtKey: kde_KSSLPKCS12_fromString((qt_QString *) [base64 toQString: &_qstring_base64], (qt_QString *) [password toQString: &_qstring_password]) withClass: [KSSLPKCS12 class] allocatedInObjcWorld: YES];
}

+ (KSSLPKCS12*) fromString: (NSString *)base64 
{
static qt_QString * _qstring_base64 = 0L;
	return (KSSLPKCS12*) [QtSupport objectForQtKey: kde_KSSLPKCS12_fromString((qt_QString *) [base64 toQString: &_qstring_base64], "") withClass: [KSSLPKCS12 class] allocatedInObjcWorld: YES];
}

+ (KSSLPKCS12*) loadCertFile: (NSString *)filename password: (NSString *)password
{
static qt_QString * _qstring_password = 0L;
static qt_QString * _qstring_filename = 0L;
	return (KSSLPKCS12*) [QtSupport objectForQtKey: kde_KSSLPKCS12_loadCertFile((qt_QString *) [filename toQString: &_qstring_filename], (qt_QString *) [password toQString: &_qstring_password]) withClass: [KSSLPKCS12 class] allocatedInObjcWorld: YES];
}

+ (KSSLPKCS12*) loadCertFile: (NSString *)filename 
{
static qt_QString * _qstring_filename = 0L;
	return (KSSLPKCS12*) [QtSupport objectForQtKey: kde_KSSLPKCS12_loadCertFile((qt_QString *) [filename toQString: &_qstring_filename], "") withClass: [KSSLPKCS12 class] allocatedInObjcWorld: YES];
}

- init
{
	if ([self qt] == 0L) {
		[self setQt: kde_new_KSSLPKCS12()];
		[self setAllocatedInObjcWorld: YES];
		[QtSupport setObject: self forQtKey: [self qt]];
	}
	[super init];
	return self;
}

- (BOOL) parsePassword: (NSString *)pass
{
static qt_QString * _qstring_pass = 0L;
	return (BOOL) kde_KSSLPKCS12_parse((kde_KSSLPKCS12 *)[self qt], (qt_QString *) [pass toQString: &_qstring_pass]);
}

@end
