See ChangeLog

Monotone-Parent: 6bd02ef1f10a4cfb8e4199f21aebc3e20539ebca
Monotone-Revision: 4bf1d5199159aabb88dec15bd4be9362748e3ba1

Monotone-Author: ludovic@Sophos.ca
Monotone-Date: 2010-12-29T13:01:16
Monotone-Branch: ca.inverse.sogo
This commit is contained in:
Ludovic Marcotte
2010-12-29 13:01:16 +00:00
parent f25db2f502
commit 13798939bf
5 changed files with 75 additions and 49 deletions
+51 -1
View File
@@ -1,8 +1,9 @@
/* NSString+Utilities.m - this file is part of SOGo
*
* Copyright (C) 2006-2009 Inverse inc.
* Copyright (C) 2006-2011 Inverse inc.
*
* Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
* Ludovic Marcotte <lmarcotte@inverse.ca>
*
* This file is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -39,6 +40,12 @@
#import "NSString+Utilities.h"
#define _XOPEN_SOURCE 1
#include <unistd.h>
#include <openssl/evp.h>
#include <openssl/md5.h>
#include <openssl/sha.h>
static NSMutableCharacterSet *urlNonEndingChars = nil;
static NSMutableCharacterSet *urlAfterEndingChars = nil;
static NSMutableCharacterSet *urlStartChars = nil;
@@ -538,4 +545,47 @@ static NSMutableCharacterSet *safeLDIFStartChars = nil;
return object;
}
- (NSString *) asCryptString
{
char *buf;
// The salt is weak here, but who cares anyway, crypt should not
// be used anymore
buf = (char *)crypt([self UTF8String], [self UTF8String]);
return [NSString stringWithUTF8String: buf];
}
- (NSString *) asMD5String
{
unsigned char md[MD5_DIGEST_LENGTH];
char buf[80];
int i;
memset(md, 0, MD5_DIGEST_LENGTH);
memset(buf, 0, 80);
EVP_Digest((const void *) [self UTF8String], strlen([self UTF8String]), md, NULL, EVP_md5(), NULL);
for (i = 0; i < MD5_DIGEST_LENGTH; i++)
sprintf(&(buf[i*2]), "%02x", md[i]);
return [NSString stringWithUTF8String: buf];
}
- (NSString *) asSHA1String
{
unsigned char sha[SHA_DIGEST_LENGTH];
char buf[80];
int i;
memset(sha, 0, SHA_DIGEST_LENGTH);
memset(buf, 0, 80);
SHA1((const void *)[self UTF8String], strlen([self UTF8String]), sha);
for (i = 0; i < SHA_DIGEST_LENGTH; i++)
sprintf(&(buf[i*2]), "%02x", sha[i]);
return [NSString stringWithUTF8String: buf];
}
@end