app-starlock/star_lock/lib/blue/io_protocol/io_getPublicKey.dart
2023-08-12 18:32:49 +08:00

70 lines
1.8 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 'dart:typed_data';
import '../../tools/storage.dart';
import '../io_tool/io_tool.dart';
import '../sender_manage.dart';
import 'io_reply.dart';
import 'io_sender.dart';
import 'io_type.dart';
class GetPublicKeyCommand extends SenderProtocol {
String? lockID;
GetPublicKeyCommand({
this.lockID,
}) : super(CommandType.getLockPublicKey);
@override
List<int> messageDetail() {
List<int> data = [];
// 指令类型
int type = commandType!.typeValue;
double typeDouble = type/256;
int type1 = typeDouble.toInt();
int type2 = type%256;
data.add(type1);
data.add(type2);
// print("type:$type");
// print("type1:$type1");
// print("type2:$type2");
print("lockID${lockID!} lockID.utf8.encode${utf8.encode(lockID!)}");
int length = utf8.encode(lockID!).length;
data.addAll(utf8.encode(lockID!));
data = getFixedLengthList(data, 40 - length);
// print("dataaaaaa:$data");
return data;
}
}
class GetPublicKeyReply extends Reply {
GetPublicKeyReply.parseData(CommandType commandType, List<int> dataDetail)
: super.parseData(commandType, dataDetail) {
var tokenData = dataDetail.sublist(3);
print('获取公钥:dataDetail$dataDetail tokenData:$tokenData');
switch(dataDetail[2]){
case 0x00:
//成功
String stringEncoded = base64.encode(tokenData);
print('获取公钥成功 publickey:$stringEncoded');
// 储存公钥
// Storage.setData("bluePublicKey", stringEncoded);
IoSenderManage.getPrivateKey("TMH_c3570480da8d", "1", "1", 1, tokenData, 1);
break;
case 0x07:
//无权限
break;
case 0x0f:
//用户已存在
break;
default:
//失败
break;
}
}
}