tuve que ingeniarme para sacar los hashes de un archivo .txt.asc por eso esta clase.
que opinan ustedes, es un buen planteo? es pésimo? no esta bien construida la clase?
que mejoras le harían?
espero sus comentarios....
' gambas class file
'Clase txtasc by postapase 28/12/2016
Public Const SHA1 As String = "SHA1"
Public Const SHA256 As String = "SHA256"
Public Const SHA512 As String = "SHA512"
Public Const FALLO As String = "FALLO"
Private Const COMIENZO As String = "-----BEGIN PGP SIGNED MESSAGE-----"
Private Const HASH As String = "Hash:"
Private Const FINAL As String = "-----BEGIN PGP SIGNATURE-----"
Property TipoHash As String
Property HashDistro As Collection
Private $TipoHash As String
Private $HashDistro As New Collection
Public Sub _new(RutaArchivo As String) ''Ingresar ruta de archivo *.txt.asc
Dim archivo As File
Dim parrafo As String
Dim tipo As String
Dim CorteTipoHash As New String[]
Dim CorteHash As New String[]
Dim Contenido As String
Dim integridad As Byte = 1
If Not Exist(RutaArchivo) Then
Debug Error.Text
Return
Endif
archivo = Open RutaArchivo For Read
While Not Eof(archivo)
Line Input #archivo, parrafo
Print "parrafo=" & parrafo
Select Case integridad
Case 1
If InStr(parrafo, COMIENZO) = 0 Then
Debug "integridad de archivo dañada(Linea 47- If InStr(parrafo, COMIENZO) = 0"
TipoHash_Write(FALLO)
Return
Endif
Case 2
If InStr(parrafo, HASH) = 0 Then
Debug "integridad de archivo dañada (Linea 53-If InStr(parrafo, HASH) = 0)"
TipoHash_Write(FALLO)
Return
Endif
End Select
If InStr(parrafo, FINAL) <> 0 Then Break
If InStr(parrafo, HASH) <> 0 Then
CorteTipoHash = Split(parrafo, " ", Null, True)
QueTipoDeHashEs(Trim(CorteTipoHash[1]))
Endif
If InStr(parrafo, COMIENZO) = 0 And If InStr(parrafo, HASH) = 0 And If Not IsNull(parrafo) Then
CorteHash = Split(parrafo, " ", Null, True)
If CorteHash.Count <> 2 Or If CorteHash.Count = 0 Then
Continue
$HashDistro.Add(Trim(CorteHash[0]), Trim(CorteHash[1]))
Endif
Endif
Inc integridad
Wend
Close #archivo
HashDistro_Write($HashDistro)
End
Private Function TipoHash_Read() As String
Return $TipoHash
End
Private Sub TipoHash_Write(Value As String)
$TipoHash = Value
End
Private Function HashDistro_Read() As Collection
Return $HashDistro
End
Private Sub HashDistro_Write(Value As Collection)
$HashDistro = Value
End
Private Sub QueTipoDeHashEs(texto As String)
Select Case texto
Case SHA1
$TipoHash = SHA1
Case SHA256
$TipoHash = SHA256
Case SHA512
$TipoHash = SHA512
Case Else
$TipoHash = ""
End Select
TipoHash_Write($TipoHash)
End
'Clase txtasc by postapase 28/12/2016
Public Const SHA1 As String = "SHA1"
Public Const SHA256 As String = "SHA256"
Public Const SHA512 As String = "SHA512"
Public Const FALLO As String = "FALLO"
Private Const COMIENZO As String = "-----BEGIN PGP SIGNED MESSAGE-----"
Private Const HASH As String = "Hash:"
Private Const FINAL As String = "-----BEGIN PGP SIGNATURE-----"
Property TipoHash As String
Property HashDistro As Collection
Private $TipoHash As String
Private $HashDistro As New Collection
Public Sub _new(RutaArchivo As String) ''Ingresar ruta de archivo *.txt.asc
Dim archivo As File
Dim parrafo As String
Dim tipo As String
Dim CorteTipoHash As New String[]
Dim CorteHash As New String[]
Dim Contenido As String
Dim integridad As Byte = 1
If Not Exist(RutaArchivo) Then
Debug Error.Text
Return
Endif
archivo = Open RutaArchivo For Read
While Not Eof(archivo)
Line Input #archivo, parrafo
Print "parrafo=" & parrafo
Select Case integridad
Case 1
If InStr(parrafo, COMIENZO) = 0 Then
Debug "integridad de archivo dañada(Linea 47- If InStr(parrafo, COMIENZO) = 0"
TipoHash_Write(FALLO)
Return
Endif
Case 2
If InStr(parrafo, HASH) = 0 Then
Debug "integridad de archivo dañada (Linea 53-If InStr(parrafo, HASH) = 0)"
TipoHash_Write(FALLO)
Return
Endif
End Select
If InStr(parrafo, FINAL) <> 0 Then Break
If InStr(parrafo, HASH) <> 0 Then
CorteTipoHash = Split(parrafo, " ", Null, True)
QueTipoDeHashEs(Trim(CorteTipoHash[1]))
Endif
If InStr(parrafo, COMIENZO) = 0 And If InStr(parrafo, HASH) = 0 And If Not IsNull(parrafo) Then
CorteHash = Split(parrafo, " ", Null, True)
If CorteHash.Count <> 2 Or If CorteHash.Count = 0 Then
Continue
$HashDistro.Add(Trim(CorteHash[0]), Trim(CorteHash[1]))
Endif
Endif
Inc integridad
Wend
Close #archivo
HashDistro_Write($HashDistro)
End
Private Function TipoHash_Read() As String
Return $TipoHash
End
Private Sub TipoHash_Write(Value As String)
$TipoHash = Value
End
Private Function HashDistro_Read() As Collection
Return $HashDistro
End
Private Sub HashDistro_Write(Value As Collection)
$HashDistro = Value
End
Private Sub QueTipoDeHashEs(texto As String)
Select Case texto
Case SHA1
$TipoHash = SHA1
Case SHA256
$TipoHash = SHA256
Case SHA512
$TipoHash = SHA512
Case Else
$TipoHash = ""
End Select
TipoHash_Write($TipoHash)
End