Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add support for InstallOperation_ZERO #31

Merged
merged 1 commit into from
May 30, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion payload.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"bytes"
"compress/bzip2"
"crypto/sha256"
"encoding/binary"
Expand Down Expand Up @@ -286,14 +287,26 @@ func (p *Payload) Extract(partition *chromeos_update_engine.PartitionUpdate, out
}
break

case chromeos_update_engine.InstallOperation_ZERO:
reader := bytes.NewReader(make([]byte, expectedUncompressedBlockSize))
n, err := io.Copy(out, reader)
if err != nil {
return err
}

if n != expectedUncompressedBlockSize {
return fmt.Errorf("Verify failed (Unexpected bytes written): %s (%d != %d)", name, n, expectedUncompressedBlockSize)
}
break

default:
return fmt.Errorf("Unhandled operation type: %s", operation.GetType().String())
}

// verify hash
hash := hex.EncodeToString(bufSha.Sum(nil))
expectedHash := hex.EncodeToString(operation.GetDataSha256Hash())
if hash != expectedHash {
if expectedHash != "" && hash != expectedHash {
return fmt.Errorf("Verify failed (Checksum mismatch): %s (%s != %s)", name, hash, expectedHash)
}
}
Expand Down