app-starlock/star_lock/lib/blue/io_protocol/io_getStarLockStatusInfo.dart
2024-04-26 15:38:59 +08:00

69 lines
1.9 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import 'dart:convert';
import 'package:get/get.dart';
import '../../app_settings/app_settings.dart';
import '../io_reply.dart';
import '../io_sender.dart';
import '../io_tool/io_tool.dart';
import '../io_type.dart';
import '../sm4Encipher/sm4.dart';
class GetStarLockStatuInfoCommand extends SenderProtocol {
String? lockID;
String? userID;
List<int>? privateKey;
GetStarLockStatuInfoCommand({
this.lockID,
this.userID,
this.privateKey
}) : super(CommandType.readStarLockStatusInfo);
@override
List<int> messageDetail() {
List<int> data = [];
List<int> ebcData = [];
// 指令类型
int type = commandType!.typeValue;
double typeDouble = type / 256;
int type1 = typeDouble.toInt();
int type2 = type % 256;
data.add(type1);
data.add(type2);
// 锁id 40
int lockIDLength = utf8.encode(lockID!).length;
data.addAll(utf8.encode(lockID!));
data = getFixedLengthList(data, 40 - lockIDLength);
//userID 要接受钥匙的用户的useid 20
int userIDLength = utf8.encode(userID!).length;
data.addAll(utf8.encode(userID!));
data = getFixedLengthList(data, 20 - userIDLength);
if ((data.length % 16) != 0) {
int add = (16 - data.length % 16);
for (int i = 0; i < add; i++) {
data.add(0);
}
}
AppLog.log("App发给锁的数据指令类型是:${commandType!.typeName} 加密之前数据是:$data");
// 拿到数据之后通过LockId进行SM4 ECB加密 key:544d485f633335373034383064613864
ebcData = SM4.encrypt(data, key: privateKey, mode: SM4CryptoMode.ECB);
return ebcData;
}
}
class GetStarLockStatuInfoReply extends Reply {
GetStarLockStatuInfoReply.parseData(CommandType commandType, List<int> dataDetail)
: super.parseData(commandType, dataDetail) {
data = dataDetail;
int status = data[2];
errorWithStstus(status);
}
}