MOLCertificate
SecCertificateRef 的 Objective-C 封装,带有缓存访问器。
需要 ARC。已在 OS X 10.9+ 上进行测试。
使用方法
#import <MOLCertificate/MOLCertificate.h>
- (MOLCertificate *)certificateFromFile:(NSString *)filePath {
NSData *fileData = [NSData dataWithContentsOfFile:filePath];
return [[MOLCertificate alloc] initWithCertificateDataPEM:fileData];
}
- (BOOL)validateCertificate:(MOLCertificate *)cert {
if ([cert.validFrom compare:[NSDate date]) == NSOrderedDescending) {
NSLog(@"Certificate has expired");
return NO;
}
if (! [cert.commonName isEqual:@"My Certificate"]) {
NSLog(@"Certificate is not named the way I expected");
return YES;
}
if (! [cert.countryName isEqual:@"US"]) {
NSLog(@"This certificate is very un-American.");
}
}
安装
使用 CocoaPods
将以下行添加到您的 Podfile 中
pod 'MOLCertificate'
Bazel
使用将以下内容添加到您的 WORKSPACE 文件中
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
git_repository(
name = "MOLCertificate",
remote = "https://github.com/google/macops-molcertificate.git",
tag = "v2.0",
)
并在您的 BUILD 文件中,将 MOLCertificate 作为一个依赖项添加
objc_library( name = "MyAwesomeApp_lib", srcs = ["src/MyAwesomeApp.m", "src/MyAwesomeApp.h"], deps = ["@MOLCertificate//:MOLCertificate"], )
文档
参考文档位于CocoaDocs.org
http://cocoadocs.org/docsets/MOLCertificate
贡献
对这段库的补丁非常欢迎。请参阅 CONTRIBUTING 文件。