image

package
v0.0.24 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 1, 2021 License: Apache-2.0 Imports: 23 Imported by: 8

README

Mynewt Images

Anatomy

    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    |                            Header                             |
    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    ~                      Padding (optional)                       ~
    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    ~                                                               ~
    ~                                                               ~
    ~                             Body                              ~
    ~                                                               ~
    ~                                                               ~
    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    |                 Protected Trailer (optional)                  |
    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    ~                                                               ~
    ~                   Protected TLVs (optional)                   ~
    ~                                                               ~
    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    |                            Trailer                            |
    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    ~                                                               ~
    ~                             TLVs                              ~
    ~                                                               ~
    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

All fields are in host-byte order (typically little endian).

Header
     0                   1                   2                   3
     0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    |                      Magic (0x96f3b83d)                       |
    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    |                     Reserved1 (0x00000000)                    |
    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    |          Header size          |        Protected size         |
    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    |                           Body size                           |
    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    |                             Flags                             |
    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    | Major version | Minor version |           Revision            |
    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    |                         Build number                          |
    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    |                     Reserved2 (0x00000000)                    |
    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Field Description Notes
Magic Identifies the start of an image
Header size 32 + the amount of padding that follows the header
Protected size Size, in bytes, of the protected trailer PLUS the protected TLVs 0 if no protected TLVs
Body size Size, in bytes, of the image body
Flags One bit per flag See below
Major version The first element of the version number major.minor.revision.build
Minor version The second element of the version number major.minor.revision.build
Revision The third element of the version number major.minor.revision.build
Build number The fourth element of the version number No meaning in semver
Body

The executable itself. In encrypted images, this is the encrypted portion.

Protected trailer

Describes the set of protected TLVs that follow. This trailer is NOT present if there are no protected TLVs.

     0                   1                   2                   3
     0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    |        Magic (0x6908)         |        Protected size         |
    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Field Description Notes
Magic Identifies the start of the protected trailer
Protected size Size, in bytes, of the protected trailer PLUS the protected TLVs Identical to "Protected size" in image header
Protected TLVs

A sequence of TLV structures (see "TLVs" section for specifics). The structure of these TLVs is identical to the non-protected TLVs. The difference is that these TLVs are included as input to the image hash.

Trailer

Describes the set of TLVs that follow. This trailer is always present.

     0                   1                   2                   3
     0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    |        Magic (0x6907)         |             Size              |
    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Field Description Notes
Magic Identifies the start of the trailer
Size Size, in bytes, of the trailer PLUS the TLVs
TLVs

The TLVs (type-length-value) are a sequence of variable length structures containing image metadata.

     0                   1                   2                   3
     0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    |     Type      | Reserved (00) |            Length             |
    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    ~                                                               ~
    ~                             Body                              ~
    ~                                                               ~
    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Field Description Notes
Type Identifies the type of data in the TLV body
Length The length, in bytes, of the TLV body
Body Varies by type

Header flags

Each header flag is represented by a single bit. As with the other numeric fields, the flags field is in host byte order.

Value Description Notes
0x00000004 Encrypted by key in TLV Implies the presence of an "enc" TLV
0x00000010 Non-bootable Second half of a split image

TLV types

Value Description Notes
0x01 Key hash SHA256 of image verification key
0x10 SHA256 SHA256 of parts of the image (see below)
0x20 Signature: RSA2048
0x21 Signature: ECDSA224
0x22 Signature: ECDSA256
0x23 Signature: RSA3072
0x24 Signature: ED25519
0x30 Key-encrypting key: RSA
0x31 Key-encrypting key: KEK
0x32 Key-encrypting key: EC256
0x50 Encryption nonce
0x60 Secret index Indicates hardware-specific location of encryption key
SHA256

The sha256 is calculated using the following inputs:

  • Header
  • Post-header padding
  • Unencrypted image body
  • Protected trailer (if present)
  • Protected TLVs (if present)

Documentation

Index

Constants

View Source
const (
	IMAGE_MAGIC              = 0x96f3b83d /* Image header magic */
	IMAGE_TRAILER_MAGIC      = 0x6907     /* TLV info magic */
	IMAGE_PROT_TRAILER_MAGIC = 0x6908     /* Protected TLV info magic */
)
View Source
const (
	IMAGE_HEADER_SIZE  = 32
	IMAGE_TRAILER_SIZE = 4
	IMAGE_TLV_SIZE     = 4 /* Plus `value` field. */
)
View Source
const (
	IMAGE_F_PIC          = 0x00000001
	IMAGE_F_ENCRYPTED    = 0x00000004 /* encrypted image */
	IMAGE_F_NON_BOOTABLE = 0x00000010 /* non bootable image */
)

* Image header flags.

View Source
const (
	IMAGE_TLV_KEYHASH          = 0x01
	IMAGE_TLV_SHA256           = 0x10
	IMAGE_TLV_RSA2048          = 0x20
	IMAGE_TLV_ECDSA224         = 0x21
	IMAGE_TLV_ECDSA256         = 0x22
	IMAGE_TLV_RSA3072          = 0x23
	IMAGE_TLV_ED25519          = 0x24
	IMAGE_TLV_ENC_RSA          = 0x30
	IMAGE_TLV_ENC_KEK          = 0x31
	IMAGE_TLV_ENC_EC256        = 0x32
	IMAGE_TLV_AES_NONCE_LEGACY = 0x50
	IMAGE_TLV_SECRET_ID_LEGACY = 0x60
	IMAGE_TLV_AES_NONCE        = 0xa1
	IMAGE_TLV_SECRET_ID        = 0xa2
	IMAGE_TLV_SECTION          = 0xa3
)

* Image trailer TLV types.

View Source
const (
	IMAGEv1_F_PIC                      = 0x00000001
	IMAGEv1_F_SHA256                   = 0x00000002 /* Image contains hash TLV */
	IMAGEv1_F_PKCS15_RSA2048_SHA256    = 0x00000004 /* PKCS15 w/RSA2048 and SHA256 */
	IMAGEv1_F_ECDSA224_SHA256          = 0x00000008 /* ECDSA224 over SHA256 */
	IMAGEv1_F_NON_BOOTABLE             = 0x00000010 /* non bootable image */
	IMAGEv1_F_ECDSA256_SHA256          = 0x00000020 /* ECDSA256 over SHA256 */
	IMAGEv1_F_PKCS1_PSS_RSA2048_SHA256 = 0x00000040 /* RSA-PSS w/RSA2048 and SHA256 */
)
View Source
const (
	IMAGEv1_TLV_SHA256   = 1
	IMAGEv1_TLV_RSA2048  = 2
	IMAGEv1_TLV_ECDSA224 = 3
	IMAGEv1_TLV_ECDSA256 = 4
)
View Source
const IMAGEv1_MAGIC = 0x96f3b83c /* Image header magic */

Variables

View Source
var UseRsaPss = false

Set this to enable RSA-PSS for RSA signatures, instead of PKCS#1 v1.5. Eventually, this should be the default.

Functions

func GeneratePlainSecret

func GeneratePlainSecret() ([]byte, error)

GeneratePlainSecret randomly generates a 16-byte image-encrypting secret.

func GenerateSig

func GenerateSig(key sec.PrivSignKey, hash []byte) (sec.Sig, error)

GenerateSig signs an image.

func GenerateSigEc

func GenerateSigEc(key sec.PrivSignKey, hash []byte) ([]byte, error)

GenerateSig signs an image using an ec key.

func GenerateSigEd25519 added in v0.0.3

func GenerateSigEd25519(key sec.PrivSignKey, hash []byte) ([]byte, error)

GenerateSig signs an image using an ed25519 key.

func GenerateSigRsa

func GenerateSigRsa(key sec.PrivSignKey, hash []byte) ([]byte, error)

GenerateSig signs an image using an rsa key.

func ImageTlvTypeIsSecret added in v0.0.2

func ImageTlvTypeIsSecret(tlvType uint8) bool

func ImageTlvTypeIsSig

func ImageTlvTypeIsSig(tlvType uint8) bool

func ImageTlvTypeIsValid

func ImageTlvTypeIsValid(tlvType uint8) bool

func ImageTlvTypeName

func ImageTlvTypeName(tlvType uint8) string

func ImageTlvTypeToSigType added in v0.0.9

func ImageTlvTypeToSigType(tlvType uint8) (sec.SigType, bool)

Types

type ECDSASig

type ECDSASig struct {
	R *big.Int
	S *big.Int
}

type Image

type Image struct {
	Header   ImageHdr
	Pad      []byte
	Body     []byte
	ProtTlvs []ImageTlv
	Tlvs     []ImageTlv
}

func Decrypt added in v0.0.2

func Decrypt(img Image, privEncKey sec.PrivEncKey) (Image, error)

Decrypt decrypts an image body and strips the "secret" TLV. It does NOT clear the "encrypted" flag in the image header.

func DecryptHw added in v0.0.17

func DecryptHw(img Image, secret []byte) (Image, error)

DecryptHw decrypts a hardware-encrypted image. It does NOT strip the "nonce" or "secret ID" protected TLVs.

func DecryptHwFull added in v0.0.17

func DecryptHwFull(img Image, secret []byte) (Image, error)

DecryptHw decrypts a hardware-encrypted image and strips the "nonce" and "secret ID" protected TLVs.

func Encrypt added in v0.0.2

func Encrypt(img Image, pubEncKey sec.PubEncKey) (Image, error)

Encrypt encrypts an image body and adds a "secret" TLV. It does NOT set the "encrypted" flag in the image header.

func GenerateImage

func GenerateImage(opts ImageCreateOpts) (Image, error)

GenerateImage produces an Image object from a set of image creation options.

func ParseImage

func ParseImage(imgData []byte) (Image, error)

func ReadImage

func ReadImage(filename string) (Image, error)

func (*Image) Bin added in v0.0.23

func (img *Image) Bin() ([]byte, error)

func (*Image) CalcHash

func (i *Image) CalcHash(initialHash []byte) ([]byte, error)

CalcHash calculates a SHA256 of the given image. initialHash should be nil for non-split-images.

func (*Image) Clone added in v0.0.2

func (img *Image) Clone() Image

Clone performs a deep copy of an image.

func (*Image) CollectSecret added in v0.0.2

func (img *Image) CollectSecret() ([]byte, error)

CollectSecret finds the "secret" TLV in an image and returns its body. It returns nil if there is no "secret" TLV.

func (*Image) CollectSigs

func (img *Image) CollectSigs() ([]sec.Sig, error)

CollectSigs returns a slice of all signatures present in an image's trailer.

func (*Image) ExtractSecret added in v0.0.2

func (img *Image) ExtractSecret() ([]byte, error)

ExtractSecret finds the "secret" TLV in an image, removes it, and returns its body. It returns nil if there is no "secret" TLV.

func (*Image) FindAllTlvs added in v0.0.11

func (i *Image) FindAllTlvs(tlvType uint8) []*ImageTlv

func (*Image) FindAllTlvsIf added in v0.0.11

func (i *Image) FindAllTlvsIf(pred func(tlv ImageTlv) bool) []*ImageTlv

func (*Image) FindAllUniqueTlv added in v0.0.11

func (i *Image) FindAllUniqueTlv(tlvType uint8) (*ImageTlv, error)

func (*Image) FindProtTlvIndices added in v0.0.11

func (img *Image) FindProtTlvIndices(tlvType uint8) []int

FindProtTlvIndices searches an image for TLVs of the specified type and returns their indices.

func (*Image) FindProtTlvIndicesIf added in v0.0.11

func (img *Image) FindProtTlvIndicesIf(pred func(tlv ImageTlv) bool) []int

FindProtTlvIndicesIf searches an image for TLVs satisfying the given predicate and returns their indices.

func (*Image) FindProtTlvs added in v0.0.11

func (img *Image) FindProtTlvs(tlvType uint8) []*ImageTlv

FindProtTlvs retrieves all TLVs in an image's footer with the specified type.

func (*Image) FindProtTlvsIf added in v0.0.11

func (img *Image) FindProtTlvsIf(pred func(tlv ImageTlv) bool) []*ImageTlv

FindTlvIndices searches an image for TLVs satisfying the given predicate and returns them.

func (*Image) FindProtUniqueTlv added in v0.0.11

func (i *Image) FindProtUniqueTlv(tlvType uint8) (*ImageTlv, error)

FindProtUniqueTlv retrieves a TLV in an image's footer with the specified type. It returns an error if there is more than one TLV with this type.

func (*Image) FindTlvIndices

func (img *Image) FindTlvIndices(tlvType uint8) []int

FindTlvIndices searches an image for TLVs of the specified type and returns their indices.

func (*Image) FindTlvIndicesIf added in v0.0.2

func (img *Image) FindTlvIndicesIf(pred func(tlv ImageTlv) bool) []int

FindTlvIndicesIf searches an image for TLVs satisfying the given predicate and returns their indices.

func (*Image) FindTlvs

func (img *Image) FindTlvs(tlvType uint8) []*ImageTlv

FindTlvs retrieves all TLVs in an image's footer with the specified type.

func (*Image) FindTlvsIf added in v0.0.2

func (img *Image) FindTlvsIf(pred func(tlv ImageTlv) bool) []*ImageTlv

FindTlvIndices searches an image for TLVs satisfying the given predicate and returns them.

func (*Image) FindUniqueTlv

func (i *Image) FindUniqueTlv(tlvType uint8) (*ImageTlv, error)

FindUniqueTlv retrieves a TLV in an image's footer with the specified type. It returns an error if there is more than one TLV with this type.

func (*Image) HasEncryptionPayload added in v0.0.23

func (img *Image) HasEncryptionPayload() bool

HasEncryptionPayload indicates whether an image's contains a HW encryption payload.

func (*Image) Hash

func (i *Image) Hash() ([]byte, error)

Hash retrieves the contents of an image's SHA256 TLV.

func (*Image) IsEncrypted added in v0.0.2

func (img *Image) IsEncrypted() bool

IsEncrypted indicates whether an image's "encrypted" flag is set.

func (*Image) Json

func (img *Image) Json() (string, error)

Json produces a JSON representation of an image.

func (*Image) Map

func (img *Image) Map() (map[string]interface{}, error)

Map produces a JSON-friendly map representation of an image.

func (*Image) Offsets

func (i *Image) Offsets() (ImageOffsets, error)

Offsets returns the offsets of each of an image's components if it were serialized.

func (*Image) ProtTrailer added in v0.0.8

func (img *Image) ProtTrailer() ImageTrailer

ProtTrailer constructs a protected ImageTrailer corresponding to the given image.

func (*Image) RemoveProtTlvsIf added in v0.0.11

func (i *Image) RemoveProtTlvsIf(pred func(tlv ImageTlv) bool) []ImageTlv

RemoveProtTlvsIf removes all TLVs from an image that satisfy the supplied predicate. It returns a slice of the removed TLVs.

func (*Image) RemoveProtTlvsWithType added in v0.0.11

func (i *Image) RemoveProtTlvsWithType(tlvType uint8) []ImageTlv

RemoveProtTlvsWithType removes from an image all TLVs with the specified type. It returns a slice of the removed TLVs.

func (*Image) RemoveTlvsIf

func (i *Image) RemoveTlvsIf(pred func(tlv ImageTlv) bool) []ImageTlv

RemoveTlvsIf removes all TLVs from an image that satisfy the supplied predicate. It returns a slice of the removed TLVs.

func (*Image) RemoveTlvsWithType

func (i *Image) RemoveTlvsWithType(tlvType uint8) []ImageTlv

RemoveTlvsWithType removes from an image all TLVs with the specified type. It returns a slice of the removed TLVs.

func (*Image) TotalSize

func (i *Image) TotalSize() (int, error)

TotalSize returns the size of the image if it were serialized, in bytes.

func (*Image) Trailer

func (img *Image) Trailer() ImageTrailer

Trailer constructs an ImageTrailer corresponding to the given image.

func (*Image) VerifyHash added in v0.0.2

func (img *Image) VerifyHash(privEncKeys []sec.PrivEncKey) (int, error)

VerifyHash calculates an image's hash and compares it to the image's SHA256 TLV. If the image is encrypted, this function temporarily decrypts it before calculating the hash. The returned int is the index of the key that was used to decrypt the image, or -1 if none. An error is returned if the hash is incorrect.

func (*Image) VerifyManifest

func (img *Image) VerifyManifest(man manifest.Manifest) error

VerifyManifest compares an image's structure to its manifest. It returns an error if the image doesn't match the manifest.

func (*Image) VerifySigs added in v0.0.2

func (img *Image) VerifySigs(keys []sec.PubSignKey) (int, error)

VerifySigs checks an image's attached signatures against the provided set of keys. It succeeds if the image has no signatures or if any signature can be verified. The returned int is the index of the key that was used to verify a signature, or -1 if none. An error is returned if there is at least one signature and they all fail the check.

func (*Image) VerifyStructure added in v0.0.2

func (img *Image) VerifyStructure() error

VerifyStructure checks an image's structure for internal consistency. It returns an error if the image is incorrect.

func (*Image) Write

func (i *Image) Write(w io.Writer) (int, error)

Write serializes and writes a Mynewt image.

func (*Image) WritePlusOffsets

func (i *Image) WritePlusOffsets(w io.Writer) (ImageOffsets, error)

WritePlusOffsets writes a binary image to the given writer. It returns the offsets of the image components that got written.

func (*Image) WriteToFile

func (i *Image) WriteToFile(filename string) error

WriteToFile writes a Mynewt image to a file.

type ImageCreateOpts

type ImageCreateOpts struct {
	SrcBinFilename    string
	SrcEncKeyFilename string
	SrcEncKeyIndex    int
	Version           ImageVersion
	SigKeys           []sec.PrivSignKey
	Sections          []Section
	LoaderHash        []byte
	HdrPad            int
	ImagePad          int
	UseLegacyTLV      bool
}

type ImageCreator

type ImageCreator struct {
	Body         []byte
	Version      ImageVersion
	SigKeys      []sec.PrivSignKey
	Sections     []Section
	HWKeyIndex   int
	Nonce        []byte
	PlainSecret  []byte
	CipherSecret []byte
	HeaderSize   int
	InitialHash  []byte
	Bootable     bool
	UseLegacyTLV bool
}

func NewImageCreator

func NewImageCreator() ImageCreator

func (*ImageCreator) Create

func (ic *ImageCreator) Create() (Image, error)

Create produces an Image object.

func (*ImageCreator) CreateV1

func (ic *ImageCreator) CreateV1() (ImageV1, error)

type ImageHdr

type ImageHdr struct {
	Magic  uint32
	Pad1   uint32
	HdrSz  uint16
	ProtSz uint16
	ImgSz  uint32
	Flags  uint32
	Vers   ImageVersion
	Pad3   uint32
}

func (*ImageHdr) Map

func (h *ImageHdr) Map(offset int) map[string]interface{}

type ImageHdrV1

type ImageHdrV1 struct {
	Magic uint32
	TlvSz uint16
	KeyId uint8
	Pad1  uint8
	HdrSz uint16
	Pad2  uint16
	ImgSz uint32
	Flags uint32
	Vers  ImageVersion
	Pad3  uint32
}

type ImageOffsets

type ImageOffsets struct {
	Header      int
	Body        int
	ProtTrailer int
	Trailer     int
	ProtTlvs    []int
	Tlvs        []int
	TotalSize   int
}

type ImageTlv

type ImageTlv struct {
	Header ImageTlvHdr
	Data   []byte
}

func BuildKeyHashTlv

func BuildKeyHashTlv(keyBytes []byte) ImageTlv

BuildKeyHash produces a key-hash TLV given a public verification key. Users do not normally need to call this. Call BuildSigTlvs instead.

func BuildSigTlvs

func BuildSigTlvs(keys []sec.PrivSignKey, hash []byte) ([]ImageTlv, error)

BuildSigTlvs signs an image and creates a pair of TLVs representing the signature.

func GenerateEncTlv

func GenerateEncTlv(cipherSecret []byte) (ImageTlv, error)

GenerateEncTlv creates an encryption-secret TLV given a secret.

func GenerateHWKeyIndexTLV added in v0.0.6

func GenerateHWKeyIndexTLV(secretIndex uint32, useLegacyTLV bool) (ImageTlv, error)

GenerateHWKeyIndexTLV creates a hardware key index TLV.

func GenerateNonceTLV added in v0.0.6

func GenerateNonceTLV(nonce []byte, useLegacyTLV bool) (ImageTlv, error)

GenerateNonceTLV creates a nonce TLV given a nonce.

func GenerateSectionTlv added in v0.0.20

func GenerateSectionTlv(section Section) (ImageTlv, error)

GenerateEncTlv creates an encryption-secret TLV given a secret.

func (*ImageTlv) Clone added in v0.0.2

func (tlv *ImageTlv) Clone() ImageTlv

func (*ImageTlv) Map

func (t *ImageTlv) Map(index int, offset int) map[string]interface{}

func (*ImageTlv) Write

func (tlv *ImageTlv) Write(w io.Writer) (int, error)

type ImageTlvHdr

type ImageTlvHdr struct {
	Type uint8
	Pad  uint8
	Len  uint16
}

type ImageTrailer

type ImageTrailer struct {
	Magic     uint16
	TlvTotLen uint16
}

func (*ImageTrailer) Map

func (t *ImageTrailer) Map(offset int) map[string]interface{}

type ImageV1

type ImageV1 struct {
	Header ImageHdrV1
	Body   []byte
	Tlvs   []ImageTlv
}

func GenerateV1Image

func GenerateV1Image(opts ImageCreateOpts) (ImageV1, error)

func (*ImageV1) FindTlvs

func (img *ImageV1) FindTlvs(tlvType uint8) []ImageTlv

func (*ImageV1) Hash

func (img *ImageV1) Hash() ([]byte, error)

func (*ImageV1) Offsets

func (img *ImageV1) Offsets() (ImageOffsets, error)

func (*ImageV1) TotalSize

func (img *ImageV1) TotalSize() (int, error)

func (*ImageV1) Write

func (img *ImageV1) Write(w io.Writer) (int, error)

func (*ImageV1) WritePlusOffsets

func (img *ImageV1) WritePlusOffsets(w io.Writer) (ImageOffsets, error)

type ImageVersion

type ImageVersion struct {
	Major    uint8
	Minor    uint8
	Rev      uint16
	BuildNum uint32
}

func ParseVersion

func ParseVersion(versStr string) (ImageVersion, error)

ParseVersion parses an image version string (e.g., "1.2.3.4")

func (ImageVersion) String

func (ver ImageVersion) String() string

type Section added in v0.0.20

type Section struct {
	Name   string
	Size   int
	Offset int
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL