/// <summary>
        /// Binds the events exposed by the source to the handlers in the listener.
        /// </summary>
        /// <param name="source">The source of instrumentation events. Must be an instance of HashAlgorithmInstrumentationProvider.</param>
        /// <param name="listener">The listener for instrumentation events. Must be an instance of HashAlgorithmInstrumentationListener.</param>
        public void Bind(object source, object listener)
        {
            HashAlgorithmInstrumentationListener castedListener = (HashAlgorithmInstrumentationListener)listener;
            HashAlgorithmInstrumentationProvider castedProvider = (HashAlgorithmInstrumentationProvider)source;

            castedProvider.cyptographicOperationFailed += castedListener.CyptographicOperationFailed;
            castedProvider.hashComparisonPerformed     += castedListener.HashComparisonPerformed;
            castedProvider.hashMismatchDetected        += castedListener.HashMismatchDetected;
            castedProvider.hashOperationPerformed      += castedListener.HashOperationPerformed;
        }
예제 #2
0
        /// <summary>
        /// Initialize a new instance of the <see cref="HashAlgorithmProvider"/> class with the <see cref="HashAlgorithm"/> type and if salt is enabled.
        /// </summary>
        /// <param name="algorithmType">The <see cref="HashAlgorithm"/> to use.</param>
        /// <param name="saltEnabled"><see langword="true"/> if salt should be applied; otherwise, <see langword="false"/>.</param>
        public HashAlgorithmProvider(Type algorithmType, bool saltEnabled)
        {
            if (algorithmType == null) throw new ArgumentNullException("algorithmType");
            if (!typeof(HashAlgorithm).IsAssignableFrom(algorithmType)) throw new ArgumentException(Resources.ExceptionMustBeAHashAlgorithm, "algorithmType");

            this.algorithmType = algorithmType;
            this.saltEnabled = saltEnabled;

            this.instrumentationProvider = new HashAlgorithmInstrumentationProvider();
        }