app-starlock/lib/blue/io_protocol/io_referEventRecordTime.dart

140 lines
3.9 KiB
Dart
Raw Normal View History

// 查询事件记录(时间查询)
2023-09-04 15:00:42 +08:00
import 'dart:convert';
import 'package:crypto/crypto.dart' as crypto;
import 'package:star_lock/tools/dateTool.dart';
2023-09-04 15:00:42 +08:00
import '../io_reply.dart';
import '../io_sender.dart';
import '../io_tool/io_tool.dart';
import '../io_type.dart';
import '../sm4Encipher/sm4.dart';
2023-09-28 18:05:23 +08:00
class SenderReferEventRecordTimeCommand extends SenderProtocol {
2023-09-04 15:00:42 +08:00
2023-09-28 18:05:23 +08:00
SenderReferEventRecordTimeCommand({
2023-09-04 15:00:42 +08:00
this.keyID,
this.userID,
this.logsCount,
this.time,
2024-07-27 14:36:35 +08:00
this.currentDate,
2023-09-04 15:00:42 +08:00
this.token,
this.needAuthor,
this.publicKey,
this.privateKey,
}) : super(CommandType.generalExtendedCommond);
2024-07-29 19:52:38 +08:00
String? keyID;
String? userID;
int? logsCount;
int? time;
int? currentDate;
List<int>? token;
int? needAuthor;
List<int>? publicKey;
List<int>? privateKey;
2023-09-04 15:00:42 +08:00
@override
String toString() {
return 'SenderReferEventRecordTimeCommand{keyID: $keyID, '
2024-07-27 14:36:35 +08:00
'userID: $userID, logsCount: $logsCount, time:$time timeStr: ${DateTool().dateIntToYMDHNString(time)}, currentDate: ${DateTool().dateIntToYMDHNString(time)}'
'token: $token, needAuthor: $needAuthor, publicKey: $publicKey, '
'privateKey: $privateKey}';
}
2023-09-04 15:00:42 +08:00
@override
List<int> messageDetail() {
final List<int> data = <int>[];
List<int> subData = <int>[];
List<int> ebcData = <int>[];
2023-09-04 15:00:42 +08:00
// 指令类型
// int type = commandType!.typeValue;
// double typeDouble = type / 256;
// int type1 = typeDouble.toInt();
// int type2 = type % 256;
// data.add(type1);
// data.add(type2);
data.addAll(intChangList(commandType!.typeValue));
2023-09-04 15:00:42 +08:00
// 子命令类型
data.add(41);
2023-09-04 15:00:42 +08:00
// keyID 40
final int keyIDLength = utf8.encode(keyID!).length;
2023-09-04 15:00:42 +08:00
subData.addAll(utf8.encode(keyID!));
subData = getFixedLengthList(subData, 40 - keyIDLength);
//userID 20
final int userIDLength = utf8.encode(userID!).length;
2023-09-04 15:00:42 +08:00
subData.addAll(utf8.encode(userID!));
subData = getFixedLengthList(subData, 20 - userIDLength);
// logsCount
subData.addAll(intChangList(logsCount!));
2023-09-04 15:00:42 +08:00
// time
subData.add((time! & 0xff000000) >> 24);
subData.add((time! & 0xff0000) >> 16);
subData.add((time! & 0xff00) >> 8);
2024-07-27 14:36:35 +08:00
subData.add(time! & 0xff);
// currentDate
subData.add((currentDate! & 0xff000000) >> 24);
subData.add((currentDate! & 0xff0000) >> 16);
subData.add((currentDate! & 0xff00) >> 8);
subData.add(currentDate! & 0xff);
2023-09-04 15:00:42 +08:00
// token
// subData.addAll(token!);
if (needAuthor == 0) {
2023-09-04 15:00:42 +08:00
//AuthCodeLen 1
subData.add(0);
} else {
final List<int> authCodeData = <int>[];
2023-09-04 15:00:42 +08:00
//authUserID
authCodeData.addAll(utf8.encode(userID!));
//KeyID
authCodeData.addAll(utf8.encode(keyID!));
//token 4 首次请求 Token 填 0如果锁需要鉴权操作者身份则会分配动态口令并在应答消息中返回二次请求时带上。
authCodeData.addAll(token!);
authCodeData.addAll(publicKey!);
// 把KeyID、authUserID、时间戳、公钥通过md5加密之后就是authCode
final crypto.Digest authCode = crypto.md5.convert(authCodeData);
2023-09-04 15:00:42 +08:00
subData.add(authCode.bytes.length);
subData.addAll(authCode.bytes);
}
data.add(subData.length);
data.addAll(subData);
if ((data.length % 16) != 0) {
final int add = 16 - data.length % 16;
2023-09-04 15:00:42 +08:00
for (int i = 0; i < add; i++) {
data.add(0);
}
}
printLog(data);
2023-09-04 15:00:42 +08:00
// 拿到数据之后通过LockId进行SM4 ECB加密 key:544d485f633335373034383064613864
ebcData = SM4.encrypt(data, key: privateKey, mode: SM4CryptoMode.ECB);
return ebcData;
}
}
2023-09-28 18:05:23 +08:00
class SenderReferEventRecordTimeReply extends Reply {
SenderReferEventRecordTimeReply.parseData(
CommandType commandType, List<int> dataDetail)
2023-09-04 15:00:42 +08:00
: super.parseData(commandType, dataDetail) {
data = dataDetail;
final int status = data[2];
errorWithStstus(status);
2023-09-04 15:00:42 +08:00
}
}