LCLicence.h

This file can be downloaded as part of milnlicence.tbz.

//
//  LCLicence.h
//  LicenceCore - https://indie.miln.eu
//
//  Copyright © Graham Miln. All rights reserved. https://miln.eu
//
//  This package is subject to the terms of the Artistic License 2.0.
//  If a copy of the Artistic-2.0 was not distributed with this file, you can
//  obtain one at https://indie.miln.eu/licence


@import Foundation;
@import Security;

NS_ASSUME_NONNULL_BEGIN

// KVO Keys
extern NSString* LCLicenceKeyIsTrusted;
extern NSString* LCLicenceKeyIsPending;
extern NSString* LCLicenceKeyError;

/** LCLicence represents a single licence. */
@interface LCLicence : NSObject
@property(assign,readonly) BOOL isTrusted; /** Trust state of the licence; available after `evaluate` been called and finished. */
@property(assign,readonly) BOOL isPending;
@property(assign,readonly) SecTrustRef trust;
@property(strong,readonly) NSError* error;
// ...
// Licence certificate properties
@property(strong,readonly) NSString* uid; /** Unique identifier for the certificate. Suitable for use as a dictionary key. */
@property(strong,readonly) NSString* label; /** Presentation label of the licence. */
@property(strong,readonly) NSString* serialNumber; /** Certificate's serial number. May be nil. */
@property(strong,readonly) NSDate* notAfter; /** Date after which the licence ceases to be valid. May be nil. */
@property(strong,readonly) NSDate* notBefore; /** Date before which the licence is not valid. May be nil. */

/** Return a unique identifier for a given certificate. Suitable for use as a dictionary key. */
+ (NSString*)uidForCertificate:(SecCertificateRef)aCertificate;

- (instancetype)initWithData:(NSData*)someData format:(SecExternalFormat)inFormat anchors:(CFArrayRef)someAnchors queue:(NSOperationQueue*)aQueue;
- (instancetype)initWithCertificate:(SecCertificateRef)aCertificate anchors:(CFArrayRef)someAnchors queue:(NSOperationQueue*)aQueue;

/** Are the two licences equal? Compares leaf certificates only. */
- (BOOL)isEqualToLicence:(LCLicence*)rhs;

/** Evaluate the licence for trust. Must be called once. Additional calls are ignored. */
- (void)evaluate;

/** Inform licence any ongoing evaulation is not needed. */
- (void)cancelEvaluation;

/** Exported certificate in PEM format. */
- (NSData*)exportAsPEMWithError:(NSError*__autoreleasing __nonnull*)outError;

@end

NS_ASSUME_NONNULL_END