MCPcopy Create free account
hub / github.com/WICG/webpackage / ObtainIntegrityBlock

Function ObtainIntegrityBlock

go/integrityblock/integrityblock.go:134–156  ·  view source on GitHub ↗

obtainIntegrityBlock returns either the existing integrity block parsed (not supported in v1) or a newly created empty integrity block. Integrity block preceeds the actual web bundle bytes. The second return value marks the offset from which point onwards we need to copy the web bundle bytes from. I

(bundleFile *os.File)

Source from the content-addressed store, hash-verified

132// needed later in the signing process (TODO) because we cannot rely on the integrity block length, because
133// we don't know if the integrity block already existed or not.
134func ObtainIntegrityBlock(bundleFile *os.File) (*IntegrityBlock, int64, error) {
135 webBundleLen, err := readWebBundlePayloadLength(bundleFile)
136 if err != nil {
137 return nil, 0, err
138 }
139 fileStats, err := bundleFile.Stat()
140 if err != nil {
141 return nil, 0, err
142 }
143
144 integrityBlockLen := fileStats.Size() - webBundleLen
145 if integrityBlockLen < 0 {
146 return nil, -1, errors.New("Integrity block length should never be negative. Web bundle length big endian seems to be bigger than the size of the file.")
147 }
148
149 if integrityBlockLen != 0 {
150 // Read existing integrity block. Not supported in v1.
151 return nil, integrityBlockLen, errors.New("Web bundle already contains an integrity block. Please provide an unsigned web bundle.")
152 }
153
154 integrityBlock := generateEmptyIntegrityBlock()
155 return integrityBlock, integrityBlockLen, nil
156}
157
158func (integrityBlock *IntegrityBlock) addNewSignatureToIntegrityBlock(signatureAttributes SignatureAttributesMap, signature []byte) {
159 is := []*IntegritySignature{{

Callers 1

SignWithIntegrityBlockFunction · 0.92

Calls 2

Tested by

no test coverage detected