Simplified `uint8_t *TLV<tagType, maxTags>::buf(tagType tag, int len)`

Also updated HAP.cpp to use new `uint8_t *TLV<tagType, maxTags>::buf(tagType tag, uint8_t *src, int len)`
This commit is contained in:
Gregg 2023-07-30 21:54:14 -05:00
parent a84429f930
commit 5a356432b3
2 changed files with 10 additions and 20 deletions

View File

@ -609,8 +609,8 @@ int HAPClient::postPairSetupURL(){
crypto_sign_detached(tlv8.buf(kTLVType_Signature,64),NULL,accessoryInfo,accessoryInfoLen,accessory.LTSK); // produce signature of accessoryInfo using AccessoryLTSK (Ed25519 long-term secret key) crypto_sign_detached(tlv8.buf(kTLVType_Signature,64),NULL,accessoryInfo,accessoryInfoLen,accessory.LTSK); // produce signature of accessoryInfo using AccessoryLTSK (Ed25519 long-term secret key)
memcpy(tlv8.buf(kTLVType_Identifier,accessoryPairingIDLen),accessoryPairingID,accessoryPairingIDLen); // set Identifier TLV record as accessoryPairingID tlv8.buf(kTLVType_Identifier,accessoryPairingID,accessoryPairingIDLen); // set Identifier TLV record as accessoryPairingID
memcpy(tlv8.buf(kTLVType_PublicKey,accessoryLTPKLen),accessoryLTPK,accessoryLTPKLen); // set PublicKey TLV record as accessoryLTPK tlv8.buf(kTLVType_PublicKey,accessoryLTPK,accessoryLTPKLen); // set PublicKey TLV record as accessoryLTPK
LOG2("------- ENCRYPTING SUB-TLVS -------\n"); LOG2("------- ENCRYPTING SUB-TLVS -------\n");
@ -722,7 +722,7 @@ int HAPClient::postPairVerifyURL(){
crypto_sign_detached(tlv8.buf(kTLVType_Signature,64),NULL,accessoryInfo,accessoryInfoLen,accessory.LTSK); // produce signature of accessoryInfo using AccessoryLTSK (Ed25519 long-term secret key) crypto_sign_detached(tlv8.buf(kTLVType_Signature,64),NULL,accessoryInfo,accessoryInfoLen,accessory.LTSK); // produce signature of accessoryInfo using AccessoryLTSK (Ed25519 long-term secret key)
memcpy(tlv8.buf(kTLVType_Identifier,accessoryPairingIDLen),accessoryPairingID,accessoryPairingIDLen); // set Identifier TLV record as accessoryPairingID tlv8.buf(kTLVType_Identifier,accessoryPairingID,accessoryPairingIDLen); // set Identifier TLV record as accessoryPairingID
LOG2("------- ENCRYPTING SUB-TLVS -------\n"); LOG2("------- ENCRYPTING SUB-TLVS -------\n");
@ -746,7 +746,7 @@ int HAPClient::postPairVerifyURL(){
tlv8.buf(kTLVType_EncryptedData,edLen); // set length of EncryptedData TLV record, which should now include the Authentication Tag at the end as required by HAP tlv8.buf(kTLVType_EncryptedData,edLen); // set length of EncryptedData TLV record, which should now include the Authentication Tag at the end as required by HAP
tlv8.val(kTLVType_State,pairState_M2); // set State=<M2> tlv8.val(kTLVType_State,pairState_M2); // set State=<M2>
memcpy(tlv8.buf(kTLVType_PublicKey,32),publicCurveKey,32); // set PublicKey to Accessory's Curve25519 public key tlv8.buf(kTLVType_PublicKey,publicCurveKey,32); // set PublicKey to Accessory's Curve25519 public key
tlvRespond(); // send response to client tlvRespond(); // send response to client
return(1); return(1);

View File

@ -178,19 +178,7 @@ uint8_t *TLV<tagType, maxTags>::buf(tagType tag){
template<class tagType, int maxTags> template<class tagType, int maxTags>
uint8_t *TLV<tagType, maxTags>::buf(tagType tag, int len){ uint8_t *TLV<tagType, maxTags>::buf(tagType tag, int len){
tlv_t *tlv=find(tag); return(buf(tag,NULL,len));
if(tlv && len<=tlv->maxLen){
tlv->len=len;
cLen+=tlv->len;
for(int i=0;i<tlv->len;i+=255)
cLen+=2;
return(tlv->val);
}
return(NULL);
} }
////////////////////////////////////// //////////////////////////////////////
@ -208,7 +196,9 @@ uint8_t *TLV<tagType, maxTags>::buf(tagType tag, uint8_t *src, int len){
for(int i=0;i<tlv->len;i+=255) for(int i=0;i<tlv->len;i+=255)
cLen+=2; cLen+=2;
if(src)
memcpy(tlv->val,src,len); memcpy(tlv->val,src,len);
return(tlv->val); return(tlv->val);
} }