/core/externals/update-engine/Common/NSData+Hash.m

http://macfuse.googlecode.com/ · Objective C · 32 lines · 12 code · 7 blank · 13 comment · 0 complexity · 5f477c86ac5f3e2a4cae0601c2d020d6 MD5 · raw file

  1. // Copyright 2008 Google Inc.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #import "NSData+Hash.h"
  15. #import <CommonCrypto/CommonDigest.h>
  16. @implementation NSData (KSDataHashAdditions)
  17. - (NSData *)SHA1Hash {
  18. CC_SHA1_CTX sha1Context;
  19. unsigned char hash[CC_SHA1_DIGEST_LENGTH];
  20. CC_SHA1_Init(&sha1Context);
  21. CC_SHA1_Update(&sha1Context, [self bytes], [self length]);
  22. CC_SHA1_Final(hash, &sha1Context);
  23. return [NSData dataWithBytes:hash length:sizeof(hash)];
  24. }
  25. @end