7237N/A/*
7237N/A * The contents of this file are subject to the terms of the Common Development and
7237N/A * Distribution License (the License). You may not use this file except in compliance with the
7237N/A * License.
7237N/A *
7237N/A * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
7237N/A * specific language governing permission and limitations under the License.
7237N/A *
7237N/A * When distributing Covered Software, include this CDDL Header Notice in each file and include
7237N/A * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
7237N/A * Header, with the fields enclosed by brackets [] replaced by your own identifying
7237N/A * information: "Portions copyright [year] [name of copyright owner]".
7237N/A *
7237N/A * Copyright 2016 ForgeRock AS.
7237N/A *
7237N/A * Portions Copyright 2014 Nathaniel McCallum, Red Hat
7237N/A */
7237N/A
7237N/A#include "base32.h"
7237N/A#include <CommonCrypto/CommonHMAC.h>
7237N/A#include <sys/time.h>
7237N/A
7237N/A#import "FRAMechanismFactory.h"
7237N/A#import "FRAIdentity.h"
7237N/A#import "FRAIdentityDatabase.h"
7237N/A#import "FRAIdentityModel.h"
7237N/A#import "FRAMechanism.h"
7237N/A#import "FRAUriMechanismReader.h"
7237N/A
7237N/A@implementation FRAUriMechanismReader {
7237N/A
7237N/A FRAIdentityDatabase *_database;
7237N/A NSMutableDictionary *_mechanisms;
7237N/A FRAIdentityModel *_identityModel;
7237N/A}
7237N/A
7237N/A#pragma mark -
7237N/A#pragma mark Lifecyle
7237N/A
7237N/A- (instancetype)initWithDatabase:(FRAIdentityDatabase *)database identityModel:(FRAIdentityModel *)identityModel {
7237N/A if (self = [super init]) {
7237N/A _database = database;
7237N/A _identityModel = identityModel;
7237N/A _mechanisms = [NSMutableDictionary dictionary];
7237N/A }
7237N/A return self;
7237N/A}
7237N/A
7237N/A- (void) addMechanismFactory:(id<FRAMechanismFactory>)factory {
7237N/A [_mechanisms setObject:factory forKey:[factory getSupportedProtocol]];
7237N/A}
7237N/A
7237N/A#pragma mark -
7237N/A#pragma mark Factory Functions
7237N/A
7237N/A- (FRAMechanism *)getMechanism:(NSURL *)url handler:(void(^)(BOOL, NSError *))handler error:(NSError *__autoreleasing *)error {
7237N/A
7237N/A NSString* scheme = [url scheme];
7237N/A
7237N/A id<FRAMechanismFactory> mechanismFactory = [_mechanisms objectForKey:scheme];
7237N/A
7237N/A return [mechanismFactory buildMechanism:url database:_database identityModel:_identityModel handler:handler error:error];
7237N/A}
7237N/A
7237N/A- (FRAMechanism *)parseFromURL:(NSURL *)url handler:(void(^)(BOOL, NSError *))handler error:(NSError *__autoreleasing *)error {
7237N/A FRAMechanism *mechanism = [self getMechanism:url handler:handler error:error];
7237N/A return mechanism;
7237N/A}
7237N/A
7237N/A- (FRAMechanism *)parseFromString:(NSString *)string handler:(void(^)(BOOL, NSError *))handler error:(NSError *__autoreleasing *)error {
7237N/A return [self parseFromURL:[[NSURL alloc]initWithString:string] handler:handler error:error];
7237N/A}
7237N/A
7237N/A@end