示例#1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Protocol"/> class.
        /// </summary>
        /// <param name="handshakePattern">The handshake pattern (e.q. NX or IK).</param>
        /// <param name="cipher">The cipher function (AESGCM or ChaChaPoly).</param>
        /// <param name="hash">The hash function (SHA256, SHA512, BLAKE2s, or BLAKE2b).</param>
        /// <param name="modifiers">The combination of pattern modifiers (e.q. empty, psk0, or psk1+psk2).</param>
        /// <exception cref="ArgumentNullException">
        /// Thrown if the either <paramref name="handshakePattern"/>,
        /// <paramref name="cipher"/>, or <paramref name="hash"/> is null.
        /// </exception>
        /// <exception cref="ArgumentException">
        /// Thrown if <paramref name="modifiers"/> does not represent a valid combination of pattern modifiers.
        /// </exception>
        public Protocol(
            HandshakePattern handshakePattern,
            CipherFunction cipher,
            HashFunction hash,
            PatternModifiers modifiers = PatternModifiers.None)
        {
            Exceptions.ThrowIfNull(handshakePattern, nameof(handshakePattern));
            Exceptions.ThrowIfNull(cipher, nameof(cipher));
            Exceptions.ThrowIfNull(hash, nameof(hash));

            HandshakePattern = handshakePattern;
            Cipher           = cipher;
            Dh        = DhFunction.Curve25519;
            Hash      = hash;
            Modifiers = modifiers;

            Name = GetName();
        }
示例#2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Protocol"/>
 /// class using ChaChaPoly, 25519, and SHA256 functions.
 /// </summary>
 /// <param name="handshakePattern">The handshake pattern (e.q. NX or IK).</param>
 /// <param name="modifiers">The combination of pattern modifiers (e.q. empty, psk0, or psk1+psk2).</param>
 /// <exception cref="ArgumentNullException">
 /// Thrown if the <paramref name="handshakePattern"/> is null.
 /// </exception>
 /// <exception cref="ArgumentException">
 /// Thrown if <paramref name="modifiers"/> does not represent a valid combination of pattern modifiers.
 /// </exception>
 public Protocol(HandshakePattern handshakePattern, PatternModifiers modifiers = PatternModifiers.None)
     : this(handshakePattern, CipherFunction.ChaChaPoly, HashFunction.Sha256, modifiers)
 {
 }