InitPacket constructor

InitPacket({
  1. List<int>? fromBytes,
  2. List<int>? hashBytes,
  3. HashType hashType = HashType.noHash,
  4. List<List<int>>? bootValidationBytes,
  5. List<ValidationType>? bootValidationType,
  6. FwType dfuType = FwType.application,
  7. bool isDebug = false,
  8. int fwVersion = 0xffffffff,
  9. int hwVersion = 0xffffffff,
  10. int sdSize = 0,
  11. int appSize = 0,
  12. int blSize = 0,
  13. List<int> sdReq = const [0xfffe],
})

Implementation

InitPacket({
  this.fromBytes,
  this.hashBytes,
  this.hashType = HashType.noHash,
  this.bootValidationBytes,
  this.bootValidationType,
  this.dfuType = FwType.application,
  this.isDebug = false,
  this.fwVersion = 0xffffffff,
  this.hwVersion = 0xffffffff,
  this.sdSize = 0,
  this.appSize = 0,
  this.blSize = 0,
  this.sdReq = const [0xfffe]
}){
  bootValidationBytes ??= [];
  bootValidationType ??= [];

  if(fromBytes != null){
    //construct from a protobuf string/buffer
    packet = pb.Packet();
    packet.mergeFromBuffer(fromBytes!); //packet.parseFromString(fromBytes);

    if(packet.hasField(1)){
      initCommand = packet.signedCommand.command.init;
    }
    else{
      initCommand = packet.command.init;
    }
  }
  else{
    //construct from input variables
    bootValidation = [];
    for(int i = 0; i < bootValidationType!.length;i++){
      ValidationType x = bootValidationType![i];
      bootValidation!.add(
        pb.BootValidation(
          type: x,
          bytes: bootValidationBytes![i]
        )
      );
    }
    //By default, set the packet's command to an unsigned command
    //If a signature is set (via setSignature), this will get overwritten
    //with an instance of SignedCommand instead.
    pb.Hash hash = pb.Hash(
      hashType: hashType,
      hash: hashBytes!
    );
    initCommand = pb.InitCommand(
      sdReq: sdReq,
      bootValidation: bootValidation,
      type: dfuType,
      isDebug: isDebug,
      fwVersion: fwVersion,
      hwVersion: hwVersion,
      sdSize: sdSize,
      blSize: blSize,
      appSize: appSize,
      hash: hash
    );
    packet = pb.Packet(
      command: pb.Command(
        opCode: OpCode.init,
        init: initCommand
      )
    );
  }
  _validate();
}