On Tue, Apr 7, 2009 at 7:57 PM, Graham Cox <graham....@bigpond.com> wrote:
> I'm doing this, which is the first step in building an NSData representation
> of the various objects, prior to SHA-1 digesting the result. Be good to know
> if this is adequate for system/architecture independence. The intention is
> that the digest only ever sees a little-endian representation of the time
> interval.
>
> @implementation NSDate (GCHash)
>
> - (NSData*)             gc_hash
> {
>        NSSwappedDouble nt = NSSwapHostDoubleToLittle([self
> timeIntervalSinceReferenceDate]);
>        return [NSData dataWithBytes:&nt length:sizeof(NSSwappedDouble)];
> }
>
> @end

If this is also how you store your dates then this is fine. If you
store them in some other way (e.g. asking the system to put them in an
plist) then this is still fine as long as you're using whole numbers
of seconds. If you can store arbitrary fractional values of seconds in
your dates, and you store them in some other way than the above, then
I would be wary: floating point math is inexact, and it's possible
that the conversion to and from the intermediate representation could
end up with a different least-significant bit.

Note that if you manually convert your date to the serialized
representation but it's not the above, then you could simply hash that
intermediate representation directly.

Mike
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to