/// <summary> /// Load the <see cref="JudgeAuthenticationOptions.JudgePublicKey"/> from the specified PEM file containing a /// RSA public key. /// </summary> /// <param name="options">The <see cref="JudgeAuthenticationOptions"/> object.</param> /// <param name="file">Path to the PEM file containing public key.</param> /// <exception cref="ArgumentNullException"> /// <paramref name="options"/> is null /// or /// <paramref name="file"/> is null. /// </exception> public static void LoadJudgePublicKeyFromCertificate(this JudgeAuthenticationOptions options, string file) { Contract.NotNull(options, nameof(options)); Contract.NotNull(file, nameof(file)); options.JudgePublicKey?.Dispose(); options.JudgePublicKey = Pem.ReadRsaKey(file); }
/// <summary> /// Initialize a new <see cref="LocalJudgeAuthenticationService"/> instance. /// </summary> /// <param name="options">Service options.</param> /// <exception cref="ArgumentNullException"><paramref name="options"/> is null.</exception> public LocalJudgeAuthenticationService(JudgeAuthenticationOptions options) { Contract.NotNull(options, nameof(options)); _options = options; _sessions = new ConcurrentDictionary <Guid, JudgeAuthenticationSession>(); _rng = new Random(); }
/// <summary> /// Add <see cref="LocalJudgeAuthenticationService"/> to the given service collection. /// </summary> /// <param name="services">Service collection.</param> /// <param name="options">A callback to manipulate options.</param> /// <exception cref="ArgumentNullException"> /// <paramref name="services"/> is null /// or /// <paramref name="options"/> is null. /// </exception> public static IServiceCollection AddLocalJudgeAuthenticationService( this IServiceCollection services, Action <JudgeAuthenticationOptions> options) { Contract.NotNull(services, nameof(services)); Contract.NotNull(options, nameof(options)); var opt = new JudgeAuthenticationOptions(); options(opt); services.AddSingleton(opt); services.AddSingleton <IJudgeAuthenticationService, LocalJudgeAuthenticationService>(); return(services); }