PageRenderTime 32ms CodeModel.GetById 21ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 0ms

/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
15#import "NSData+Hash.h"
16
17#import <CommonCrypto/CommonDigest.h>
18
19@implementation NSData (KSDataHashAdditions)
20
21- (NSData *)SHA1Hash {
22  CC_SHA1_CTX sha1Context;
23  unsigned char hash[CC_SHA1_DIGEST_LENGTH];
24  
25  CC_SHA1_Init(&sha1Context);
26  CC_SHA1_Update(&sha1Context, [self bytes], [self length]);
27  CC_SHA1_Final(hash, &sha1Context);
28  
29  return [NSData dataWithBytes:hash length:sizeof(hash)];
30}
31
32@end