Imports System.Text
Imports System.Security.Cryptography

Namespace Security.Cryptography

    ''' <summary>
    ''' Provides detailed information for hash value construction.
    ''' </summary>
    ''' <remarks></remarks>
    Public Class HashInfo

        ''' <summary>
        ''' Initializes a default instance of the <see cref="Mercury.Mobile.Security.Cryptography.HashInfo"/> class.
        ''' </summary>
        ''' <remarks></remarks>
        Public Sub New()
            Me.New(SHA1.Create(), Encoding.Unicode)
        End Sub

        ''' <summary>
        ''' Initializes a new instance of the <see cref="Mercury.Mobile.Security.Cryptography.HashInfo"/> 
        ''' class with the specified values.
        ''' </summary>
        ''' <param name="algorithm">The hash algorithm to use.</param>
        ''' <param name="encoding">The text encoding.</param>
        ''' <remarks></remarks>
        Public Sub New(ByVal algorithm As HashAlgorithm, ByVal encoding As Encoding)
            Me.New(algorithm, encoding, 0, True)
        End Sub

        ''' <summary>
        ''' Initializes a new instance of the <see cref="Mercury.Mobile.Security.Cryptography.HashInfo"/> 
        ''' class with the specified values.
        ''' </summary>
        ''' <param name="algorithm">The hash algorithm to use.</param>
        ''' <param name="encoding">The text encoding.</param>
        ''' <param name="byteOffset">The offset applied to the byte array width 
        ''' for the precomputed, combined input values.  Default is 0.</param>
        ''' <param name="returnHex">A value indicating whether the return string 
        ''' should be formatted as hexadecimal numbers.</param>
        ''' <remarks></remarks>
        Public Sub New(ByVal algorithm As HashAlgorithm, ByVal encoding As Encoding, ByVal byteOffset As Integer, ByVal returnHex As Boolean)
            Me._algorithm = algorithm
            Me._encoding = encoding
            Me._byteOffset = byteOffset
            Me._returnHex = returnHex
        End Sub

        Private _algorithm As HashAlgorithm
        Private _encoding As Encoding
        Private _byteOffset As Integer
        Private _returnHex As Boolean

        ''' <summary>
        ''' Gets the hash algorithm to use.
        ''' </summary>
        ''' <returns>The hash algorithm to use.</returns>
        ''' <remarks></remarks>
        Public ReadOnly Property Algorithm() As HashAlgorithm
            Get
                Return Me._algorithm
            End Get
        End Property

        ''' <summary>
        ''' Gets the text encoding.
        ''' </summary>
        ''' <returns>The text encoding.</returns>
        ''' <remarks></remarks>
        Public ReadOnly Property Encoding() As Encoding
            Get
                Return Me._encoding
            End Get
        End Property

        ''' <summary>
        ''' Gets the offset applied to the byte array width for the 
        ''' precomputed, combined input values.  Default is 0.
        ''' </summary>
        ''' <returns>The offset applied to the byte array width 
        ''' for the precomputed, combined input values.</returns>
        ''' <remarks></remarks>
        Public ReadOnly Property ByteOffset() As Integer
            Get
                Return Me._byteOffset
            End Get
        End Property

        ''' <summary>
        ''' Gets a value indicating whether the return string should be formatted as hexadecimal numbers. 
        ''' </summary>
        ''' <returns>True if the return string should be formatted as hexadecimal numbers; otherwise, false.</returns>
        ''' <remarks></remarks>
        Public ReadOnly Property ReturnHex() As Boolean
            Get
                Return Me._returnHex
            End Get
        End Property

    End Class

End Namespace