コード例 #1
0
        /// <summary>Parses the <see cref="ReadOnlySpan{T}"/> into its <see cref="EncryptionAlgorithm"/> representation.</summary>
        public static bool TryParse(ReadOnlySpan <byte> value, [NotNullWhen(true)] out EncryptionAlgorithm?algorithm)
        {
            if (value.Length == 13)
            {
                switch (IntegerMarshal.ReadUInt64(value))
                {
                case _A128CBC_ when IntegerMarshal.ReadUInt64(value, 5) == _BC_HS256:
                    algorithm = A128CbcHS256;

                    goto Found;

                case _A192CBC_ when IntegerMarshal.ReadUInt64(value, 5) == _BC_HS384:
                    algorithm = A192CbcHS384;

                    goto Found;

                case _A256CBC_ when IntegerMarshal.ReadUInt64(value, 5) == _BC_HS512:
                    algorithm = A256CbcHS512;

                    goto Found;
                }
            }
            else if (value.Length == 7)
            {
                switch (IntegerMarshal.ReadUInt56(value))
                {
                case _A128GCM:
                    algorithm = A128Gcm;
                    goto Found;

                case _A192GCM:
                    algorithm = A192Gcm;
                    goto Found;

                case _A256GCM:
                    algorithm = A256Gcm;
                    goto Found;
                }
            }

#if NET5_0_OR_GREATER
            Unsafe.SkipInit(out algorithm);
#else
            algorithm = default;
#endif
            return(false);

Found:
            return(true);
        }
コード例 #2
0
ファイル: EncryptionAlgorithm.cs プロジェクト: watfordgnf/Jwt
        /// <summary>Parses the <see cref="ReadOnlySpan{T}"/> into its <see cref="EncryptionAlgorithm"/> representation.</summary>
        /// <param name="value"></param>
        /// <param name="algorithm"></param>
        public static bool TryParse(ReadOnlySpan <byte> value, [NotNullWhen(true)] out EncryptionAlgorithm?algorithm)
        {
            if (value.Length == 13)
            {
                switch (IntegerMarshal.ReadUInt64(value))
                {
                case _A128CBC_ when IntegerMarshal.ReadUInt64(value, 5) == _BC_HS256:
                    algorithm = A128CbcHS256;

                    goto Found;

                case _A192CBC_ when IntegerMarshal.ReadUInt64(value, 5) == _BC_HS384:
                    algorithm = A192CbcHS384;

                    goto Found;

                case _A256CBC_ when IntegerMarshal.ReadUInt64(value, 5) == _BC_HS512:
                    algorithm = A256CbcHS512;

                    goto Found;
                }
            }
            else if (value.Length == 7)
            {
                switch (IntegerMarshal.ReadUInt56(value))
                {
                case _A128GCM:
                    algorithm = A128Gcm;
                    goto Found;

                case _A192GCM:
                    algorithm = A192Gcm;
                    goto Found;

                case _A256GCM:
                    algorithm = A256Gcm;
                    goto Found;
                }
            }

            algorithm = null;
            return(false);

Found:
            return(true);
        }