NSData+Mnemonic.m
author Jens Alfke <jens@mooseyard.com>
Wed Sep 02 08:41:25 2009 -0700 (2009-09-02)
changeset 35 5cab3034d3a1
permissions -rw-r--r--
10.6 compatibility: Fix some new compiler warnings, and work around apparent regressions in NSTask and -stringByStandardizingPath.
jens@33
     1
//
jens@33
     2
//  NSData+Mnemonic.m
jens@33
     3
//  Cloudy
jens@33
     4
//
jens@33
     5
//  Created by Jens Alfke on 6/24/09.
jens@33
     6
//  Copyright 2009 Jens Alfke. All rights reserved.
jens@33
     7
//
jens@33
     8
jens@33
     9
#import "NSData+Mnemonic.h"
jens@33
    10
#import "mnemonic.h"
jens@33
    11
jens@33
    12
jens@33
    13
@implementation NSData (Mnemonic)
jens@33
    14
jens@33
    15
- (NSString*) my_mnemonic {
jens@33
    16
    NSMutableData *chars = [NSMutableData dataWithLength: 10*mn_words_required(self.length)];
jens@33
    17
    if (!chars)
jens@33
    18
        return nil;
jens@33
    19
    int result = mn_encode((void*)self.bytes, self.length,
jens@33
    20
                           chars.mutableBytes, chars.length,
jens@33
    21
                           MN_FDEFAULT);
jens@33
    22
    if (result != 0) {
jens@33
    23
        Warn(@"Mnemonic encoder failed: err=%i",result);
jens@33
    24
        return nil;
jens@33
    25
    }
jens@33
    26
    return [[[NSString alloc] initWithUTF8String: chars.mutableBytes] autorelease];
jens@33
    27
}
jens@33
    28
jens@33
    29
@end