• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Need localization-proof method of transporting dates.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Need localization-proof method of transporting dates.


  • Subject: Re: Need localization-proof method of transporting dates.
  • From: Greg Guerin <email@hidden>
  • Date: Sun, 5 Apr 2009 18:18:51 -0700

Michael Ash wrote:

@implementation NSDictionary (SHA1Hashing)
- (NSData *)gc_sha1hash {
    NSMutableData *subhashes = [NSMutableData data];
    for(id key in [[self allKeys]
sortedArrayUsingSelector:@selector(compare:)]) {
        [subhashes appendData:[key gc_sha1hash]];
        [subhashes appendData:[[self objectForKey:key] gc_sha1hash]];
    }
    return [subhashes gc_sha1hash];
}
@end

Then define -gc_sha1hash for all the other classes you expect to
encounter as well. (The prefix is just to ensure that you don't
overwrite a hypothetical Apple implementation of a -sha1hash method.)


As a design, it might be more flexible to define a -gc_canonicalData method that returns an NSData containing unhashed canonical bytes, rather than -gc_sha1hash that returns a hash. This would make it easier to use different secure-hash algorithms, should that be desired. SHA1 isn't exactly state-of-the-art.

I'd also make the code that calculates the hash from a given NSDictionary or NSArray return an error (or throw an exception) if anything in the collection doesn't respond to -gc_canonicalData. Or it could silently skip those (not hash them), depending on the context.

  -- GG

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Need localization-proof method of transporting dates.
      • From: Michael Ash <email@hidden>
  • Prev by Date: Re: Cocoa user pane equivalent?
  • Next by Date: Re: Cocoa user pane equivalent?
  • Previous by thread: Re: Need localization-proof method of transporting dates.
  • Next by thread: Re: Need localization-proof method of transporting dates.
  • Index(es):
    • Date
    • Thread