Skip to content

Commit

Permalink
Merge pull request ethereum#497 from dinhln89/v1
Browse files Browse the repository at this point in the history
Fixed change panic to log error for encrypt/decrypt secret and openin…
  • Loading branch information
ngtuna authored Apr 22, 2019
2 parents 95dff6e + 28cd1ed commit 4fc27f2
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion consensus/posv/posv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func TestGetM1M2FromCheckpointHeader(t *testing.T) {
Epoch: uint64(epoch),
},
}
testMoveM2 := []uint64{0,0,0,1,1,1,2,2,2,0,0,0,1,1,1,2,2,2}
testMoveM2 := []uint64{0, 0, 0, 1, 1, 1, 2, 2, 2, 0, 0, 0, 1, 1, 1, 2, 2, 2}
//try from block 3410001 to 3410018
for i := uint64(3464001); i <= 3464018; i++ {
currentNumber := int64(i)
Expand Down
12 changes: 8 additions & 4 deletions contracts/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -503,15 +503,17 @@ func Encrypt(key []byte, text string) string {

block, err := aes.NewCipher(key)
if err != nil {
panic(err)
log.Error("Fail to encrypt", "err", err)
return ""
}

// The IV needs to be unique, but not secure. Therefore it's common to
// include it at the beginning of the ciphertext.
ciphertext := make([]byte, aes.BlockSize+len(plaintext))
iv := ciphertext[:aes.BlockSize]
if _, err := io.ReadFull(cryptoRand.Reader, iv); err != nil {
panic(err)
log.Error("Fail to encrypt iv", "err", err)
return ""
}

stream := cipher.NewCFBEncrypter(block, iv)
Expand All @@ -527,13 +529,15 @@ func Decrypt(key []byte, cryptoText string) string {

block, err := aes.NewCipher(key)
if err != nil {
panic(err)
log.Error("Fail to decrypt", "err", err)
return ""
}

// The IV needs to be unique, but not secure. Therefore it's common to
// include it at the beginning of the ciphertext.
if len(ciphertext) < aes.BlockSize {
panic("ciphertext too short")
log.Error("ciphertext too short")
return ""
}
iv := ciphertext[:aes.BlockSize]
ciphertext = ciphertext[aes.BlockSize:]
Expand Down
4 changes: 2 additions & 2 deletions eth/downloader/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ func (d *Downloader) syncWithPeer(p *peerConnection, hash common.Hash, td *big.I
}(time.Now())

// Look up the sync boundaries: the common ancestor and the target block
latest, err := d.fetchHeight(p,hash)
latest, err := d.fetchHeight(p, hash)
if err != nil {
return err
}
Expand Down Expand Up @@ -541,7 +541,7 @@ func (d *Downloader) Terminate() {

// fetchHeight retrieves the head header of the remote peer to aid in estimating
// the total time a pending synchronisation would take.
func (d *Downloader) fetchHeight(p *peerConnection,hash common.Hash) (*types.Header, error) {
func (d *Downloader) fetchHeight(p *peerConnection, hash common.Hash) (*types.Header, error) {

// Request the advertised remote head block and wait for the response
go p.peer.RequestHeadersByHash(hash, 1, 0, false)
Expand Down

0 comments on commit 4fc27f2

Please sign in to comment.