File: structs.go

package info (click to toggle)
relic 7.6.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,108 kB
  • sloc: sh: 230; makefile: 10
file content (105 lines) | stat: -rw-r--r-- 2,144 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
//
// Copyright (c) SAS Institute Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

package cabfile

import "crypto"

const Magic = 0x4643534d // MSCF

type CabinetFlag uint16

const (
	FlagPrevCabinet CabinetFlag = 1 << iota
	FlagNextCabinet
	FlagReservePresent
)

type Header struct {
	Magic       uint32
	Reserved1   uint32
	TotalSize   uint32
	Reserved2   uint32
	OffsetFiles uint32
	Reserved3   uint32
	Version     uint16
	NumFolders  uint16
	NumFiles    uint16
	Flags       CabinetFlag
	SetID       uint16
	CabNumber   uint16
}

const reserveHeaderSize = 4

type ReserveHeader struct {
	HeaderSize uint16
	FolderSize uint8
	DataSize   uint8
}

const signatureHeaderSize = 20

type SignatureHeader struct {
	Unknown1           uint32
	CabinetSize        uint32
	SignatureSize      uint32
	Unknown2, Unknown3 uint32
}

func (sh *SignatureHeader) Size() uint32 {
	if sh == nil {
		return 0
	}
	return sh.SignatureSize
}

type FolderHeader struct {
	Offset      uint32
	NumData     uint16
	Compression uint16
}

// the pieces of Header that are part of the signature
type sigBlob struct {
	// skipped fields: Reserved1, CabNumber
	Magic       uint32
	TotalSize   uint32
	Reserved2   uint32
	OffsetFiles uint32
	Reserved3   uint32
	Version     uint16
	NumFolders  uint16
	NumFiles    uint16
	Flags       CabinetFlag
	SetID       uint16
	SigUnknown3 uint32
}

type Cabinet struct {
	Header          Header
	ReserveHeader   ReserveHeader
	ReserveData     []byte
	SignatureHeader *SignatureHeader
	Signature       []byte
}

type CabinetDigest struct {
	Cabinet  *Cabinet
	Imprint  []byte
	HashFunc crypto.Hash
	Patched  []byte
}