add blocksCount to LoadCommandStream
This commit is contained in:
parent
53689712e6
commit
10c8e16065
|
@ -4,6 +4,7 @@ import (
|
||||||
"archive/zip"
|
"archive/zip"
|
||||||
"bytes"
|
"bytes"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"math"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
@ -15,12 +16,15 @@ var internalFiles = []string{
|
||||||
"Method", "StaticField", "Export", "ConstantPool", "RefLocation",
|
"Method", "StaticField", "Export", "ConstantPool", "RefLocation",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const blockSize = 247 // 255 - 8 bytes for MAC
|
||||||
|
|
||||||
// LoadCommandStream implement a struct that generates multiple Load commands used to load files to smartcards.
|
// LoadCommandStream implement a struct that generates multiple Load commands used to load files to smartcards.
|
||||||
type LoadCommandStream struct {
|
type LoadCommandStream struct {
|
||||||
data *bytes.Reader
|
data *bytes.Reader
|
||||||
currentIndex uint8
|
currentIndex uint8
|
||||||
currentData []byte
|
currentData []byte
|
||||||
p1 uint8
|
p1 uint8
|
||||||
|
blocksCount int
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewLoadCommandStream returns a new LoadCommandStream to load the specified file.
|
// NewLoadCommandStream returns a new LoadCommandStream to load the specified file.
|
||||||
|
@ -36,19 +40,24 @@ func NewLoadCommandStream(file *os.File) (*LoadCommandStream, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
return &LoadCommandStream{
|
return &LoadCommandStream{
|
||||||
data: bytes.NewReader(data),
|
data: bytes.NewReader(data),
|
||||||
p1: P1LoadMoreBlocks,
|
p1: P1LoadMoreBlocks,
|
||||||
|
blocksCount: int(math.Ceil(float64(len(data)) / float64(blockSize))),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// BlocksCount returns the total number of blocks based on data length and blockSize
|
||||||
|
func (lcs *LoadCommandStream) BlocksCount() int {
|
||||||
|
return lcs.blocksCount
|
||||||
|
}
|
||||||
|
|
||||||
// Next returns initialize the data for the next Load command.
|
// Next returns initialize the data for the next Load command.
|
||||||
// TODO:@pilu update blockSize when using encrypted data
|
// TODO:@gravityblast update blockSize when using encrypted data
|
||||||
func (lcs *LoadCommandStream) Next() bool {
|
func (lcs *LoadCommandStream) Next() bool {
|
||||||
if lcs.data.Len() == 0 {
|
if lcs.data.Len() == 0 {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
blockSize := 247 // 255 - 8 bytes for MAC
|
|
||||||
buf := make([]byte, blockSize)
|
buf := make([]byte, blockSize)
|
||||||
n, err := lcs.data.Read(buf)
|
n, err := lcs.data.Read(buf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue