Imports System
Imports System.IO

Public Class PackageStore
    Private ErrorString As String

    Public Sub New()

    End Sub

    Public Function GetError() As String
        Return ErrorString
    End Function

    ' return 1 if success, 0 if invalid console ID, -1 if error
    Public Function GetKeyVault(ByVal KVFilename As String, ByRef KeyVault As Byte()) As Integer
        Dim fs_kv As FileStream

        If KeyVault.Length <> &H3FE8 Then
            Return -1
        End If

        ' load keyvault
        Try
            fs_kv = File.OpenRead(KVFilename)
        Catch ex As Exception
            ErrorString = "Could not open keyvault file"
            Return -1
        End Try

        If fs_kv.Length = 16360 Then
            fs_kv.Read(KeyVault, 0, KeyVault.Length)
        ElseIf fs_kv.Length = 16368 Then
            fs_kv.Read(KeyVault, 0, 8)
            fs_kv.Read(KeyVault, 0, KeyVault.Length)
        Else
            ErrorString = "Keyvault file is unexpected size"
            Return -1
        End If

        fs_kv.Close()

        Return 1
    End Function
End Class
