| 1 | /* |
| 2 | ** CWMD5.h |
| 3 | ** |
| 4 | ** Copyright (c) 2002-2006 Ludovic Marcotte |
| 5 | ** |
| 6 | ** Author: Ludovic Marcotte <[email protected]> |
| 7 | ** |
| 8 | ** This library is free software; you can redistribute it and/or |
| 9 | ** modify it under the terms of the GNU Lesser General Public |
| 10 | ** License as published by the Free Software Foundation; either |
| 11 | ** version 2.1 of the License, or (at your option) any later version. |
| 12 | ** |
| 13 | ** This library is distributed in the hope that it will be useful, |
| 14 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 | ** Lesser General Public License for more details. |
| 17 | ** |
| 18 | ** You should have received a copy of the GNU General Public License |
| 19 | ** along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 20 | */ |
| 21 | |
| 22 | #ifndef _Pantomime_H_CWMD5 |
| 23 | #define _Pantomime_H_CWMD5 |
| 24 | |
| 25 | #import <Foundation/NSData.h> |
| 26 | #import <Foundation/NSObject.h> |
| 27 | #import <Foundation/NSString.h> |
| 28 | |
| 29 | /*! |
| 30 | @class CWMD5 |
| 31 | @abstract MD5 Message-Digest algorithm implementation. |
| 32 | @discussion This class provides an easy interface to the MD5 Message-Digest algorithm. |
| 33 | This algorithm is described in RFC 1321. It also supports the HMAC |
| 34 | keyed-hashing for message authentication (described in RFC 2104). HMAC |
| 35 | is used in the CRAM-MD5 SASL authentication mechanim. |
| 36 | */ |
| 37 | @interface CWMD5 : NSObject |
| 38 | { |
| 39 | @private |
| 40 | NSData *_data; |
| 41 | |
| 42 | BOOL _has_computed_digest; |
| 43 | unsigned char _digest[16]; |
| 44 | } |
| 45 | |
| 46 | /*! |
| 47 | @method initWithData: |
| 48 | @discussion This is the designated initializer for the CWMD5 class. |
| 49 | @param theData The data to use for the MD5 operation. |
| 50 | @result An instance of CWMD5, nil on failure. |
| 51 | */ |
| 52 | - (id) initWithData: (NSData *) theData; |
| 53 | |
| 54 | /*! |
| 55 | @method computeDigest |
| 56 | @discussion This method is used to compute the MD5 digest |
| 57 | for the instance's data. |
| 58 | */ |
| 59 | - (void) computeDigest; |
| 60 | |
| 61 | /*! |
| 62 | @method digest |
| 63 | @discussion This method is used to obtain the computed digest, |
| 64 | from the instance's data. |
| 65 | @result The digest, as a NSData instance. |
| 66 | */ |
| 67 | - (NSData *) digest; |
| 68 | |
| 69 | /*! |
| 70 | @method digestAsString |
| 71 | @discussion See -digest. |
| 72 | @result Returns the digest as a NSString instance. |
| 73 | */ |
| 74 | - (NSString *) digestAsString; |
| 75 | |
| 76 | /*! |
| 77 | @method hmacAsStringUsingPassword: |
| 78 | @discussion Computes the HMAC using <i>thePassword</i> and returns it. |
| 79 | @param thePassword The password to use when computing the HMAC. |
| 80 | @result The computed HMAC, as a NSString instance. |
| 81 | */ |
| 82 | - (NSString *) hmacAsStringUsingPassword: (NSString *) thePassword; |
| 83 | |
| 84 | @end |
| 85 | |
| 86 | #endif // _Pantomime_H_CWMD5 |