NSData+Mnemonic.m
changeset 33 d52f6b0d94be
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/NSData+Mnemonic.m	Wed Jul 01 14:04:56 2009 -0700
     1.3 @@ -0,0 +1,29 @@
     1.4 +//
     1.5 +//  NSData+Mnemonic.m
     1.6 +//  Cloudy
     1.7 +//
     1.8 +//  Created by Jens Alfke on 6/24/09.
     1.9 +//  Copyright 2009 Jens Alfke. All rights reserved.
    1.10 +//
    1.11 +
    1.12 +#import "NSData+Mnemonic.h"
    1.13 +#import "mnemonic.h"
    1.14 +
    1.15 +
    1.16 +@implementation NSData (Mnemonic)
    1.17 +
    1.18 +- (NSString*) my_mnemonic {
    1.19 +    NSMutableData *chars = [NSMutableData dataWithLength: 10*mn_words_required(self.length)];
    1.20 +    if (!chars)
    1.21 +        return nil;
    1.22 +    int result = mn_encode((void*)self.bytes, self.length,
    1.23 +                           chars.mutableBytes, chars.length,
    1.24 +                           MN_FDEFAULT);
    1.25 +    if (result != 0) {
    1.26 +        Warn(@"Mnemonic encoder failed: err=%i",result);
    1.27 +        return nil;
    1.28 +    }
    1.29 +    return [[[NSString alloc] initWithUTF8String: chars.mutableBytes] autorelease];
    1.30 +}
    1.31 +
    1.32 +@end