예제 #1
0
        /// <summary>
        /// Constructor fo <see cref="BaseNEncoder"/>.
        /// </summary>
        /// <param name="baseNAlphabet"></param>
        public BaseNEncoder(BaseNAlphabet baseNAlphabet)
        {
            if (baseNAlphabet == null)
            {
                throw new ArgumentNullException(nameof(baseNAlphabet));
            }

            this.Alphabet = baseNAlphabet;
        }
예제 #2
0
        /// <summary>
        /// Constructor of <see cref="BaseNDecoder"/>.
        /// </summary>
        /// <param name="baseNAlphabet"></param>
        public BaseNDecoder(BaseNAlphabet baseNAlphabet)
        {
            if (baseNAlphabet == null)
            {
                throw new ArgumentNullException(nameof(baseNAlphabet));
            }

            this.Alphabet      = baseNAlphabet;
            this.algorithmType = this.Alphabet.Alphabet.Length switch
            {
                16 => ALGORITHM_TYPE_BASE_16,
                32 => ALGORITHM_TYPE_BASE_32,
                64 => ALGORITHM_TYPE_BASE_64,
                _ => ALGORITHM_TYPE_OTHER
            };
        }
예제 #3
0
        /// <summary>
        /// Constructor of <see cref="BaseNEncoding"/>
        /// </summary>
        /// <param name="baseNAlphabet">Alphabet used as base for encoding binary data.</param>
        /// <param name="encodingName">Name of encoding. Used for <see cref="Encoding.EncodingName"/> property.</param>
        public BaseNEncoding(BaseNAlphabet baseNAlphabet, string encodingName)
        {
            if (baseNAlphabet == null)
            {
                throw new ArgumentNullException(nameof(baseNAlphabet));
            }
            if (encodingName == null)
            {
                throw new ArgumentNullException(nameof(encodingName));
            }

            this.EncodingName = encodingName;
            this.Alphabet     = baseNAlphabet;

            this.encoder = new BaseNEncoder(baseNAlphabet);
            this.decoder = new BaseNDecoder(baseNAlphabet);
        }
예제 #4
0
        /// <summary>
        /// Create BaseN decoding stream based on passed <paramref name="stream"/>.
        /// </summary>
        /// <param name="stream">Input stream with encoded data.</param>
        /// <param name="baseNAlphabet">Decoding alphabet.</param>
        /// <param name="leaveOpen">Leave <paramref name="stream"/> open when returned <see cref="Stream"/> is closed.</param>
        /// <returns>Read-only decoding stream.</returns>
        public static Stream BaseNDecode(this Stream stream, BaseNAlphabet baseNAlphabet
#if NETCOREAPP
                                         , bool leaveOpen = false
#endif
                                         )
        {
            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream));
            }
            if (baseNAlphabet == null)
            {
                throw new ArgumentNullException(nameof(baseNAlphabet));
            }

            return(new CryptoStream(stream, new BaseNEncoder(baseNAlphabet), CryptoStreamMode.Read
#if NETCOREAPP
                                    , leaveOpen
#endif
                                    ));
        }