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:
parent
a84429f930
commit
5a356432b3
12
src/HAP.cpp
12
src/HAP.cpp
|
|
@ -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)
|
||||
|
||||
memcpy(tlv8.buf(kTLVType_Identifier,accessoryPairingIDLen),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_Identifier,accessoryPairingID,accessoryPairingIDLen); // set Identifier TLV record as accessoryPairingID
|
||||
tlv8.buf(kTLVType_PublicKey,accessoryLTPK,accessoryLTPKLen); // set PublicKey TLV record as accessoryLTPK
|
||||
|
||||
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)
|
||||
|
||||
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");
|
||||
|
||||
|
|
@ -744,9 +744,9 @@ int HAPClient::postPairVerifyURL(){
|
|||
|
||||
LOG2("---------- END SUB-TLVS! ----------\n");
|
||||
|
||||
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>
|
||||
memcpy(tlv8.buf(kTLVType_PublicKey,32),publicCurveKey,32); // set PublicKey to Accessory's Curve25519 public key
|
||||
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.buf(kTLVType_PublicKey,publicCurveKey,32); // set PublicKey to Accessory's Curve25519 public key
|
||||
|
||||
tlvRespond(); // send response to client
|
||||
return(1);
|
||||
|
|
|
|||
18
src/TLV.h
18
src/TLV.h
|
|
@ -178,19 +178,7 @@ uint8_t *TLV<tagType, maxTags>::buf(tagType tag){
|
|||
template<class tagType, int maxTags>
|
||||
uint8_t *TLV<tagType, maxTags>::buf(tagType tag, int len){
|
||||
|
||||
tlv_t *tlv=find(tag);
|
||||
|
||||
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);
|
||||
return(buf(tag,NULL,len));
|
||||
}
|
||||
|
||||
//////////////////////////////////////
|
||||
|
|
@ -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)
|
||||
cLen+=2;
|
||||
|
||||
memcpy(tlv->val,src,len);
|
||||
if(src)
|
||||
memcpy(tlv->val,src,len);
|
||||
|
||||
return(tlv->val);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue