diff --git a/src/darwin/Framework/CHIP/MTRBaseDevice.mm b/src/darwin/Framework/CHIP/MTRBaseDevice.mm index 6fb6b0aac72546..149ab78a91748f 100644 --- a/src/darwin/Framework/CHIP/MTRBaseDevice.mm +++ b/src/darwin/Framework/CHIP/MTRBaseDevice.mm @@ -28,6 +28,8 @@ #import "MTRFramework.h" #import "MTRLogging_Internal.h" #import "MTRSetupPayload_Internal.h" +#import "NSDataSpanConversion.h" +#import "NSStringSpanConversion.h" #include "app/ConcreteAttributePath.h" #include "app/ConcreteCommandPath.h" @@ -522,26 +524,27 @@ id _Nullable MTRDecodeDataValueDictionaryFromCHIPTLV(chip::TLV::TLVReader * data dictionaryWithObjectsAndKeys:MTRDoubleValueType, MTRTypeKey, [NSNumber numberWithDouble:val], MTRValueKey, nil]; } case chip::TLV::kTLVType_UTF8String: { - uint32_t len = data->GetLength(); - const uint8_t * ptr; - CHIP_ERROR err = data->GetDataPtr(ptr); + CharSpan stringValue; + CHIP_ERROR err = data->Get(stringValue); if (err != CHIP_NO_ERROR) { MTR_LOG_ERROR("Error(%s): TLV UTF8String decoding failed", chip::ErrorStr(err)); return nil; } - return [NSDictionary dictionaryWithObjectsAndKeys:MTRUTF8StringValueType, MTRTypeKey, - [[NSString alloc] initWithBytes:ptr length:len encoding:NSUTF8StringEncoding], MTRValueKey, nil]; + NSString * stringObj = AsString(stringValue); + if (stringObj == nil) { + MTR_LOG_ERROR("Error(%s): TLV UTF8String value is not actually UTF-8", err.AsString()); + return nil; + } + return @ { MTRTypeKey : MTRUTF8StringValueType, MTRValueKey : stringObj }; } case chip::TLV::kTLVType_ByteString: { - uint32_t len = data->GetLength(); - const uint8_t * ptr; - CHIP_ERROR err = data->GetDataPtr(ptr); + ByteSpan bytesValue; + CHIP_ERROR err = data->Get(bytesValue); if (err != CHIP_NO_ERROR) { MTR_LOG_ERROR("Error(%s): TLV ByteString decoding failed", chip::ErrorStr(err)); return nil; } - return [NSDictionary dictionaryWithObjectsAndKeys:MTROctetStringValueType, MTRTypeKey, - [NSData dataWithBytes:ptr length:len], MTRValueKey, nil]; + return @ { MTRTypeKey : MTROctetStringValueType, MTRValueKey : AsData(bytesValue) }; } case chip::TLV::kTLVType_Null: { return [NSDictionary dictionaryWithObjectsAndKeys:MTRNullValueType, MTRTypeKey, nil]; @@ -653,7 +656,7 @@ static CHIP_ERROR MTREncodeTLVFromDataValueDictionary(id object, chip::TLV::TLVW MTR_LOG_ERROR("Error: Object to encode has corrupt UTF8 string type: %@", [value class]); return CHIP_ERROR_INVALID_ARGUMENT; } - return writer.PutString(tag, [value cStringUsingEncoding:NSUTF8StringEncoding]); + return writer.PutString(tag, [value UTF8String]); } if ([typeName isEqualToString:MTROctetStringValueType]) { if (![value isKindOfClass:[NSData class]]) { diff --git a/src/darwin/Framework/CHIP/MTRFabricInfo.mm b/src/darwin/Framework/CHIP/MTRFabricInfo.mm index 01800e7bce82c7..f0caea1e4ebeae 100644 --- a/src/darwin/Framework/CHIP/MTRFabricInfo.mm +++ b/src/darwin/Framework/CHIP/MTRFabricInfo.mm @@ -65,7 +65,7 @@ - (instancetype)initWithFabricTable:(const FabricTable &)fabricTable fabricInfo: return nil; } - _rootPublicKey = [NSData dataWithBytes:publicKey.ConstBytes() length:publicKey.Length()]; + _rootPublicKey = AsData(ByteSpan(publicKey.ConstBytes(), publicKey.Length())); _vendorID = @(fabricInfo.GetVendorId()); _fabricID = @(fabricInfo.GetFabricId()); diff --git a/src/darwin/Framework/CHIP/MTROTAProviderDelegateBridge.mm b/src/darwin/Framework/CHIP/MTROTAProviderDelegateBridge.mm index 3caacafae59533..75ea6a45ecc205 100644 --- a/src/darwin/Framework/CHIP/MTROTAProviderDelegateBridge.mm +++ b/src/darwin/Framework/CHIP/MTROTAProviderDelegateBridge.mm @@ -232,8 +232,13 @@ CHIP_ERROR OnTransferSessionBegin(TransferSession::OutputEvent & event) uint16_t fdl = 0; auto fd = mTransfer.GetFileDesignator(fdl); VerifyOrReturnError(fdl <= bdx::kMaxFileDesignatorLen, CHIP_ERROR_INVALID_ARGUMENT); + CharSpan fileDesignatorSpan(Uint8::to_const_char(fd), fdl); + + auto fileDesignator = AsString(fileDesignatorSpan); + if (fileDesignator == nil) { + return CHIP_ERROR_INCORRECT_STATE; + } - auto fileDesignator = [[NSString alloc] initWithBytes:fd length:fdl encoding:NSUTF8StringEncoding]; auto offset = @(mTransfer.GetStartOffset()); auto * controller = [[MTRDeviceControllerFactory sharedInstance] runningControllerForFabricIndex:mFabricIndex.Value()]; @@ -565,8 +570,8 @@ bool GetPeerNodeInfo(CommandHandler * commandHandler, const ConcreteCommandPath if (error != nil) { auto * desc = [error description]; auto err = [MTRError errorToCHIPErrorCode:error]; - ChipLogError(Controller, "%s: application returned error: '%s', sending error: '%s'", prefix, - [desc cStringUsingEncoding:NSUTF8StringEncoding], chip::ErrorStr(err)); + ChipLogError( + Controller, "%s: application returned error: '%s', sending error: '%s'", prefix, desc.UTF8String, err.AsString()); handler->AddStatus(cachedCommandPath, StatusIB(err).mStatus); handle.Release(); @@ -635,8 +640,7 @@ bool GetPeerNodeInfo(CommandHandler * commandHandler, const ConcreteCommandPath CommandHandler * handler = EnsureValidState(handle, cachedCommandPath, "QueryImage", data, error); VerifyOrReturn(handler != nullptr); - ChipLogDetail(Controller, "QueryImage: application responded with: %s", - [[data description] cStringUsingEncoding:NSUTF8StringEncoding]); + ChipLogDetail(Controller, "QueryImage: application responded with: %s", [[data description] UTF8String]); auto hasUpdate = [data.status isEqual:@(MTROtaSoftwareUpdateProviderOTAQueryStatusUpdateAvailable)]; auto isBDXProtocolSupported = [commandParams.protocolsSupported @@ -753,27 +757,26 @@ bool GetPeerNodeInfo(CommandHandler * commandHandler, const ConcreteCommandPath __block CommandHandler::Handle handle(commandObj); __block ConcreteCommandPath cachedCommandPath(commandPath.mEndpointId, commandPath.mClusterId, commandPath.mCommandId); - auto completionHandler - = ^(MTROTASoftwareUpdateProviderClusterApplyUpdateResponseParams * _Nullable data, NSError * _Nullable error) { - [controller - asyncDispatchToMatterQueue:^() { - assertChipStackLockedByCurrentThread(); - - CommandHandler * handler = EnsureValidState(handle, cachedCommandPath, "ApplyUpdateRequest", data, error); - VerifyOrReturn(handler != nullptr); - - ChipLogDetail(Controller, "ApplyUpdateRequest: application responded with: %s", - [[data description] cStringUsingEncoding:NSUTF8StringEncoding]); - - Commands::ApplyUpdateResponse::Type response; - ConvertFromApplyUpdateRequestResponseParms(data, response); - handler->AddResponse(cachedCommandPath, response); - handle.Release(); - } - errorHandler:^(NSError *) { - // Not much we can do here - }]; - }; + auto completionHandler = ^( + MTROTASoftwareUpdateProviderClusterApplyUpdateResponseParams * _Nullable data, NSError * _Nullable error) { + [controller + asyncDispatchToMatterQueue:^() { + assertChipStackLockedByCurrentThread(); + + CommandHandler * handler = EnsureValidState(handle, cachedCommandPath, "ApplyUpdateRequest", data, error); + VerifyOrReturn(handler != nullptr); + + ChipLogDetail(Controller, "ApplyUpdateRequest: application responded with: %s", [[data description] UTF8String]); + + Commands::ApplyUpdateResponse::Type response; + ConvertFromApplyUpdateRequestResponseParms(data, response); + handler->AddResponse(cachedCommandPath, response); + handle.Release(); + } + errorHandler:^(NSError *) { + // Not much we can do here + }]; + }; auto * commandParams = [[MTROTASoftwareUpdateProviderClusterApplyUpdateRequestParams alloc] init]; ConvertToApplyUpdateRequestParams(commandData, commandParams); diff --git a/src/darwin/Framework/CHIP/MTRThreadOperationalDataset.mm b/src/darwin/Framework/CHIP/MTRThreadOperationalDataset.mm index dc8876b870f425..bb5db0af9a977b 100644 --- a/src/darwin/Framework/CHIP/MTRThreadOperationalDataset.mm +++ b/src/darwin/Framework/CHIP/MTRThreadOperationalDataset.mm @@ -16,6 +16,7 @@ */ #import "MTRThreadOperationalDataset.h" +#import "NSDataSpanConversion.h" #include "MTRLogging_Internal.h" #include @@ -62,7 +63,7 @@ - (instancetype _Nullable)initWithNetworkName:(NSString *)networkName - (BOOL)_populateCppOperationalDataset { _cppThreadOperationalDataset.Clear(); - _cppThreadOperationalDataset.SetNetworkName([self.networkName cStringUsingEncoding:NSUTF8StringEncoding]); + _cppThreadOperationalDataset.SetNetworkName(self.networkName.UTF8String); if (![self _checkDataLength:self.extendedPANID expectedLength:MTRSizeThreadExtendedPANID]) { MTR_LOG_ERROR("Invalid ExtendedPANID"); @@ -137,9 +138,9 @@ - (instancetype _Nullable)initWithData:(NSData *)data panID = CFSwapInt16BigToHost(panID); return [self initWithNetworkName:[NSString stringWithUTF8String:networkName] - extendedPANID:[NSData dataWithBytes:extendedPANID length:MTRSizeThreadExtendedPANID] - masterKey:[NSData dataWithBytes:masterKey length:MTRSizeThreadMasterKey] - PSKc:[NSData dataWithBytes:pskc length:MTRSizeThreadPSKc] + extendedPANID:AsData(chip::ByteSpan(extendedPANID)) + masterKey:AsData(chip::ByteSpan(masterKey)) + PSKc:AsData(chip::ByteSpan(pskc)) channelNumber:@(channel) panID:[NSData dataWithBytes:&panID length:sizeof(uint16_t)]]; } @@ -147,7 +148,7 @@ - (instancetype _Nullable)initWithData:(NSData *)data - (NSData *)data { chip::ByteSpan span = _cppThreadOperationalDataset.AsByteSpan(); - return [NSData dataWithBytes:span.data() length:span.size()]; + return AsData(span); } @end diff --git a/src/darwin/Framework/CHIP/templates/MTRAttributeTLVValueDecoder-src.zapt b/src/darwin/Framework/CHIP/templates/MTRAttributeTLVValueDecoder-src.zapt index b24e063cdd06ce..71b6de6b3c0dd6 100644 --- a/src/darwin/Framework/CHIP/templates/MTRAttributeTLVValueDecoder-src.zapt +++ b/src/darwin/Framework/CHIP/templates/MTRAttributeTLVValueDecoder-src.zapt @@ -3,6 +3,8 @@ #import "MTRAttributeTLVValueDecoder_Internal.h" #import "MTRStructsObjc.h" +#import "NSStringSpanConversion.h" +#import "NSDataSpanConversion.h" #include #include diff --git a/src/darwin/Framework/CHIP/templates/MTRCallbackBridge-src.zapt b/src/darwin/Framework/CHIP/templates/MTRCallbackBridge-src.zapt index 90fc5ebeda1d70..833d8f9c3eff62 100644 --- a/src/darwin/Framework/CHIP/templates/MTRCallbackBridge-src.zapt +++ b/src/darwin/Framework/CHIP/templates/MTRCallbackBridge-src.zapt @@ -4,6 +4,8 @@ #import "MTRStructsObjc.h" #import "MTRCommandPayloadsObjc.h" #import "MTRCommandPayloads_Internal.h" +#import "NSStringSpanConversion.h" +#import "NSDataSpanConversion.h" #include diff --git a/src/darwin/Framework/CHIP/templates/MTRCommandPayloadsObjc-src.zapt b/src/darwin/Framework/CHIP/templates/MTRCommandPayloadsObjc-src.zapt index 963f425cee7d08..638a000cb8351a 100644 --- a/src/darwin/Framework/CHIP/templates/MTRCommandPayloadsObjc-src.zapt +++ b/src/darwin/Framework/CHIP/templates/MTRCommandPayloadsObjc-src.zapt @@ -5,6 +5,8 @@ #import "MTRBaseDevice_Internal.h" #import "MTRError_Internal.h" #import "MTRLogging_Internal.h" +#import "NSStringSpanConversion.h" +#import "NSDataSpanConversion.h" #include #include diff --git a/src/darwin/Framework/CHIP/templates/MTREventTLVValueDecoder-src.zapt b/src/darwin/Framework/CHIP/templates/MTREventTLVValueDecoder-src.zapt index eca3f3fa328598..470221c850066e 100644 --- a/src/darwin/Framework/CHIP/templates/MTREventTLVValueDecoder-src.zapt +++ b/src/darwin/Framework/CHIP/templates/MTREventTLVValueDecoder-src.zapt @@ -3,6 +3,8 @@ #import "MTREventTLVValueDecoder_Internal.h" #import "MTRStructsObjc.h" +#import "NSStringSpanConversion.h" +#import "NSDataSpanConversion.h" #include #include diff --git a/src/darwin/Framework/CHIP/templates/partials/decode_value.zapt b/src/darwin/Framework/CHIP/templates/partials/decode_value.zapt index 29e64683ba5062..46c4d9179696f6 100644 --- a/src/darwin/Framework/CHIP/templates/partials/decode_value.zapt +++ b/src/darwin/Framework/CHIP/templates/partials/decode_value.zapt @@ -39,9 +39,14 @@ {{#if_is_strongly_typed_bitmap type}} {{target}} = [NSNumber numberWith{{asObjectiveCNumberType "" type false}}:{{source}}.Raw()]; {{else if (isOctetString type)}} - {{target}} = [NSData dataWithBytes:{{source}}.data() length:{{source}}.size()]; + {{target}} = AsData({{source}}); {{else if (isCharString type)}} - {{target}} = [[NSString alloc] initWithBytes:{{source}}.data() length:{{source}}.size() encoding:NSUTF8StringEncoding]; + {{target}} = AsString({{source}}); + if ({{target}} == nil) { + {{! Invalid UTF-8. Just make up an error for now. }} + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + {{errorCode}} + } {{else}} {{target}} = [NSNumber numberWith{{asObjectiveCNumberType "" type false}}:{{source}}]; {{/if_is_strongly_typed_bitmap}} diff --git a/src/darwin/Framework/CHIP/zap-generated/MTRAttributeTLVValueDecoder.mm b/src/darwin/Framework/CHIP/zap-generated/MTRAttributeTLVValueDecoder.mm index 2b0f47983a3736..af82867b120000 100644 --- a/src/darwin/Framework/CHIP/zap-generated/MTRAttributeTLVValueDecoder.mm +++ b/src/darwin/Framework/CHIP/zap-generated/MTRAttributeTLVValueDecoder.mm @@ -18,6 +18,8 @@ #import "MTRAttributeTLVValueDecoder_Internal.h" #import "MTRStructsObjc.h" +#import "NSDataSpanConversion.h" +#import "NSStringSpanConversion.h" #include #include @@ -1256,7 +1258,12 @@ static id _Nullable DecodeAttributeValueForBinaryInputBasicCluster( return nil; } NSString * _Nonnull value; - value = [[NSString alloc] initWithBytes:cppValue.data() length:cppValue.size() encoding:NSUTF8StringEncoding]; + value = AsString(cppValue); + if (value == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + *aError = err; + return nil; + } return value; } case Attributes::Description::Id: { @@ -1267,7 +1274,12 @@ static id _Nullable DecodeAttributeValueForBinaryInputBasicCluster( return nil; } NSString * _Nonnull value; - value = [[NSString alloc] initWithBytes:cppValue.data() length:cppValue.size() encoding:NSUTF8StringEncoding]; + value = AsString(cppValue); + if (value == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + *aError = err; + return nil; + } return value; } case Attributes::InactiveText::Id: { @@ -1278,7 +1290,12 @@ static id _Nullable DecodeAttributeValueForBinaryInputBasicCluster( return nil; } NSString * _Nonnull value; - value = [[NSString alloc] initWithBytes:cppValue.data() length:cppValue.size() encoding:NSUTF8StringEncoding]; + value = AsString(cppValue); + if (value == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + *aError = err; + return nil; + } return value; } case Attributes::OutOfService::Id: { @@ -2015,7 +2032,7 @@ static id _Nullable DecodeAttributeValueForAccessControlCluster( auto & entry_0 = iter_0.GetValue(); MTRAccessControlClusterAccessControlExtensionStruct * newElement_0; newElement_0 = [MTRAccessControlClusterAccessControlExtensionStruct new]; - newElement_0.data = [NSData dataWithBytes:entry_0.data.data() length:entry_0.data.size()]; + newElement_0.data = AsData(entry_0.data); newElement_0.fabricIndex = [NSNumber numberWithUnsignedChar:entry_0.fabricIndex]; [array_0 addObject:newElement_0]; } @@ -2215,9 +2232,12 @@ static id _Nullable DecodeAttributeValueForActionsCluster(AttributeId aAttribute MTRActionsClusterActionStruct * newElement_0; newElement_0 = [MTRActionsClusterActionStruct new]; newElement_0.actionID = [NSNumber numberWithUnsignedShort:entry_0.actionID]; - newElement_0.name = [[NSString alloc] initWithBytes:entry_0.name.data() - length:entry_0.name.size() - encoding:NSUTF8StringEncoding]; + newElement_0.name = AsString(entry_0.name); + if (newElement_0.name == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + *aError = err; + return nil; + } newElement_0.type = [NSNumber numberWithUnsignedChar:chip::to_underlying(entry_0.type)]; newElement_0.endpointListID = [NSNumber numberWithUnsignedShort:entry_0.endpointListID]; newElement_0.supportedCommands = [NSNumber numberWithUnsignedShort:entry_0.supportedCommands.Raw()]; @@ -2249,9 +2269,12 @@ static id _Nullable DecodeAttributeValueForActionsCluster(AttributeId aAttribute MTRActionsClusterEndpointListStruct * newElement_0; newElement_0 = [MTRActionsClusterEndpointListStruct new]; newElement_0.endpointListID = [NSNumber numberWithUnsignedShort:entry_0.endpointListID]; - newElement_0.name = [[NSString alloc] initWithBytes:entry_0.name.data() - length:entry_0.name.size() - encoding:NSUTF8StringEncoding]; + newElement_0.name = AsString(entry_0.name); + if (newElement_0.name == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + *aError = err; + return nil; + } newElement_0.type = [NSNumber numberWithUnsignedChar:chip::to_underlying(entry_0.type)]; { // Scope for our temporary variables auto * array_2 = [NSMutableArray new]; @@ -2288,7 +2311,12 @@ static id _Nullable DecodeAttributeValueForActionsCluster(AttributeId aAttribute return nil; } NSString * _Nonnull value; - value = [[NSString alloc] initWithBytes:cppValue.data() length:cppValue.size() encoding:NSUTF8StringEncoding]; + value = AsString(cppValue); + if (value == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + *aError = err; + return nil; + } return value; } case Attributes::GeneratedCommandList::Id: { @@ -2449,7 +2477,12 @@ static id _Nullable DecodeAttributeValueForBasicInformationCluster( return nil; } NSString * _Nonnull value; - value = [[NSString alloc] initWithBytes:cppValue.data() length:cppValue.size() encoding:NSUTF8StringEncoding]; + value = AsString(cppValue); + if (value == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + *aError = err; + return nil; + } return value; } case Attributes::VendorID::Id: { @@ -2471,7 +2504,12 @@ static id _Nullable DecodeAttributeValueForBasicInformationCluster( return nil; } NSString * _Nonnull value; - value = [[NSString alloc] initWithBytes:cppValue.data() length:cppValue.size() encoding:NSUTF8StringEncoding]; + value = AsString(cppValue); + if (value == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + *aError = err; + return nil; + } return value; } case Attributes::ProductID::Id: { @@ -2493,7 +2531,12 @@ static id _Nullable DecodeAttributeValueForBasicInformationCluster( return nil; } NSString * _Nonnull value; - value = [[NSString alloc] initWithBytes:cppValue.data() length:cppValue.size() encoding:NSUTF8StringEncoding]; + value = AsString(cppValue); + if (value == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + *aError = err; + return nil; + } return value; } case Attributes::Location::Id: { @@ -2504,7 +2547,12 @@ static id _Nullable DecodeAttributeValueForBasicInformationCluster( return nil; } NSString * _Nonnull value; - value = [[NSString alloc] initWithBytes:cppValue.data() length:cppValue.size() encoding:NSUTF8StringEncoding]; + value = AsString(cppValue); + if (value == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + *aError = err; + return nil; + } return value; } case Attributes::HardwareVersion::Id: { @@ -2526,7 +2574,12 @@ static id _Nullable DecodeAttributeValueForBasicInformationCluster( return nil; } NSString * _Nonnull value; - value = [[NSString alloc] initWithBytes:cppValue.data() length:cppValue.size() encoding:NSUTF8StringEncoding]; + value = AsString(cppValue); + if (value == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + *aError = err; + return nil; + } return value; } case Attributes::SoftwareVersion::Id: { @@ -2548,7 +2601,12 @@ static id _Nullable DecodeAttributeValueForBasicInformationCluster( return nil; } NSString * _Nonnull value; - value = [[NSString alloc] initWithBytes:cppValue.data() length:cppValue.size() encoding:NSUTF8StringEncoding]; + value = AsString(cppValue); + if (value == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + *aError = err; + return nil; + } return value; } case Attributes::ManufacturingDate::Id: { @@ -2559,7 +2617,12 @@ static id _Nullable DecodeAttributeValueForBasicInformationCluster( return nil; } NSString * _Nonnull value; - value = [[NSString alloc] initWithBytes:cppValue.data() length:cppValue.size() encoding:NSUTF8StringEncoding]; + value = AsString(cppValue); + if (value == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + *aError = err; + return nil; + } return value; } case Attributes::PartNumber::Id: { @@ -2570,7 +2633,12 @@ static id _Nullable DecodeAttributeValueForBasicInformationCluster( return nil; } NSString * _Nonnull value; - value = [[NSString alloc] initWithBytes:cppValue.data() length:cppValue.size() encoding:NSUTF8StringEncoding]; + value = AsString(cppValue); + if (value == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + *aError = err; + return nil; + } return value; } case Attributes::ProductURL::Id: { @@ -2581,7 +2649,12 @@ static id _Nullable DecodeAttributeValueForBasicInformationCluster( return nil; } NSString * _Nonnull value; - value = [[NSString alloc] initWithBytes:cppValue.data() length:cppValue.size() encoding:NSUTF8StringEncoding]; + value = AsString(cppValue); + if (value == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + *aError = err; + return nil; + } return value; } case Attributes::ProductLabel::Id: { @@ -2592,7 +2665,12 @@ static id _Nullable DecodeAttributeValueForBasicInformationCluster( return nil; } NSString * _Nonnull value; - value = [[NSString alloc] initWithBytes:cppValue.data() length:cppValue.size() encoding:NSUTF8StringEncoding]; + value = AsString(cppValue); + if (value == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + *aError = err; + return nil; + } return value; } case Attributes::SerialNumber::Id: { @@ -2603,7 +2681,12 @@ static id _Nullable DecodeAttributeValueForBasicInformationCluster( return nil; } NSString * _Nonnull value; - value = [[NSString alloc] initWithBytes:cppValue.data() length:cppValue.size() encoding:NSUTF8StringEncoding]; + value = AsString(cppValue); + if (value == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + *aError = err; + return nil; + } return value; } case Attributes::LocalConfigDisabled::Id: { @@ -2636,7 +2719,12 @@ static id _Nullable DecodeAttributeValueForBasicInformationCluster( return nil; } NSString * _Nonnull value; - value = [[NSString alloc] initWithBytes:cppValue.data() length:cppValue.size() encoding:NSUTF8StringEncoding]; + value = AsString(cppValue); + if (value == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + *aError = err; + return nil; + } return value; } case Attributes::CapabilityMinima::Id: { @@ -3160,7 +3248,12 @@ static id _Nullable DecodeAttributeValueForLocalizationConfigurationCluster( return nil; } NSString * _Nonnull value; - value = [[NSString alloc] initWithBytes:cppValue.data() length:cppValue.size() encoding:NSUTF8StringEncoding]; + value = AsString(cppValue); + if (value == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + *aError = err; + return nil; + } return value; } case Attributes::SupportedLocales::Id: { @@ -3177,7 +3270,12 @@ static id _Nullable DecodeAttributeValueForLocalizationConfigurationCluster( while (iter_0.Next()) { auto & entry_0 = iter_0.GetValue(); NSString * newElement_0; - newElement_0 = [[NSString alloc] initWithBytes:entry_0.data() length:entry_0.size() encoding:NSUTF8StringEncoding]; + newElement_0 = AsString(entry_0); + if (newElement_0 == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + *aError = err; + return nil; + } [array_0 addObject:newElement_0]; } CHIP_ERROR err = iter_0.GetStatus(); @@ -3860,7 +3958,12 @@ static id _Nullable DecodeAttributeValueForPowerSourceCluster( return nil; } NSString * _Nonnull value; - value = [[NSString alloc] initWithBytes:cppValue.data() length:cppValue.size() encoding:NSUTF8StringEncoding]; + value = AsString(cppValue); + if (value == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + *aError = err; + return nil; + } return value; } case Attributes::WiredAssessedInputVoltage::Id: { @@ -4101,7 +4204,12 @@ static id _Nullable DecodeAttributeValueForPowerSourceCluster( return nil; } NSString * _Nonnull value; - value = [[NSString alloc] initWithBytes:cppValue.data() length:cppValue.size() encoding:NSUTF8StringEncoding]; + value = AsString(cppValue); + if (value == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + *aError = err; + return nil; + } return value; } case Attributes::BatCommonDesignation::Id: { @@ -4123,7 +4231,12 @@ static id _Nullable DecodeAttributeValueForPowerSourceCluster( return nil; } NSString * _Nonnull value; - value = [[NSString alloc] initWithBytes:cppValue.data() length:cppValue.size() encoding:NSUTF8StringEncoding]; + value = AsString(cppValue); + if (value == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + *aError = err; + return nil; + } return value; } case Attributes::BatIECDesignation::Id: { @@ -4134,7 +4247,12 @@ static id _Nullable DecodeAttributeValueForPowerSourceCluster( return nil; } NSString * _Nonnull value; - value = [[NSString alloc] initWithBytes:cppValue.data() length:cppValue.size() encoding:NSUTF8StringEncoding]; + value = AsString(cppValue); + if (value == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + *aError = err; + return nil; + } return value; } case Attributes::BatApprovedChemistry::Id: { @@ -4609,7 +4727,7 @@ static id _Nullable DecodeAttributeValueForNetworkCommissioningCluster( auto & entry_0 = iter_0.GetValue(); MTRNetworkCommissioningClusterNetworkInfo * newElement_0; newElement_0 = [MTRNetworkCommissioningClusterNetworkInfo new]; - newElement_0.networkID = [NSData dataWithBytes:entry_0.networkID.data() length:entry_0.networkID.size()]; + newElement_0.networkID = AsData(entry_0.networkID); newElement_0.connected = [NSNumber numberWithBool:entry_0.connected]; [array_0 addObject:newElement_0]; } @@ -4681,7 +4799,7 @@ static id _Nullable DecodeAttributeValueForNetworkCommissioningCluster( if (cppValue.IsNull()) { value = nil; } else { - value = [NSData dataWithBytes:cppValue.Value().data() length:cppValue.Value().size()]; + value = AsData(cppValue.Value()); } return value; } @@ -4993,9 +5111,12 @@ static id _Nullable DecodeAttributeValueForGeneralDiagnosticsCluster( auto & entry_0 = iter_0.GetValue(); MTRGeneralDiagnosticsClusterNetworkInterface * newElement_0; newElement_0 = [MTRGeneralDiagnosticsClusterNetworkInterface new]; - newElement_0.name = [[NSString alloc] initWithBytes:entry_0.name.data() - length:entry_0.name.size() - encoding:NSUTF8StringEncoding]; + newElement_0.name = AsString(entry_0.name); + if (newElement_0.name == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + *aError = err; + return nil; + } newElement_0.isOperational = [NSNumber numberWithBool:entry_0.isOperational]; if (entry_0.offPremiseServicesReachableIPv4.IsNull()) { newElement_0.offPremiseServicesReachableIPv4 = nil; @@ -5009,15 +5130,14 @@ static id _Nullable DecodeAttributeValueForGeneralDiagnosticsCluster( newElement_0.offPremiseServicesReachableIPv6 = [NSNumber numberWithBool:entry_0.offPremiseServicesReachableIPv6.Value()]; } - newElement_0.hardwareAddress = [NSData dataWithBytes:entry_0.hardwareAddress.data() - length:entry_0.hardwareAddress.size()]; + newElement_0.hardwareAddress = AsData(entry_0.hardwareAddress); { // Scope for our temporary variables auto * array_2 = [NSMutableArray new]; auto iter_2 = entry_0.IPv4Addresses.begin(); while (iter_2.Next()) { auto & entry_2 = iter_2.GetValue(); NSData * newElement_2; - newElement_2 = [NSData dataWithBytes:entry_2.data() length:entry_2.size()]; + newElement_2 = AsData(entry_2); [array_2 addObject:newElement_2]; } CHIP_ERROR err = iter_2.GetStatus(); @@ -5033,7 +5153,7 @@ static id _Nullable DecodeAttributeValueForGeneralDiagnosticsCluster( while (iter_2.Next()) { auto & entry_2 = iter_2.GetValue(); NSData * newElement_2; - newElement_2 = [NSData dataWithBytes:entry_2.data() length:entry_2.size()]; + newElement_2 = AsData(entry_2); [array_2 addObject:newElement_2]; } CHIP_ERROR err = iter_2.GetStatus(); @@ -5344,9 +5464,12 @@ static id _Nullable DecodeAttributeValueForSoftwareDiagnosticsCluster( newElement_0 = [MTRSoftwareDiagnosticsClusterThreadMetricsStruct new]; newElement_0.id = [NSNumber numberWithUnsignedLongLong:entry_0.id]; if (entry_0.name.HasValue()) { - newElement_0.name = [[NSString alloc] initWithBytes:entry_0.name.Value().data() - length:entry_0.name.Value().size() - encoding:NSUTF8StringEncoding]; + newElement_0.name = AsString(entry_0.name.Value()); + if (newElement_0.name == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + *aError = err; + return nil; + } } else { newElement_0.name = nil; } @@ -5589,9 +5712,12 @@ static id _Nullable DecodeAttributeValueForThreadNetworkDiagnosticsCluster( if (cppValue.IsNull()) { value = nil; } else { - value = [[NSString alloc] initWithBytes:cppValue.Value().data() - length:cppValue.Value().size() - encoding:NSUTF8StringEncoding]; + value = AsString(cppValue.Value()); + if (value == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + *aError = err; + return nil; + } } return value; } @@ -5636,7 +5762,7 @@ static id _Nullable DecodeAttributeValueForThreadNetworkDiagnosticsCluster( if (cppValue.IsNull()) { value = nil; } else { - value = [NSData dataWithBytes:cppValue.Value().data() length:cppValue.Value().size()]; + value = AsData(cppValue.Value()); } return value; } @@ -6345,7 +6471,7 @@ static id _Nullable DecodeAttributeValueForThreadNetworkDiagnosticsCluster( if (cppValue.IsNull()) { value = nil; } else { - value = [NSData dataWithBytes:cppValue.Value().data() length:cppValue.Value().size()]; + value = AsData(cppValue.Value()); } return value; } @@ -6552,7 +6678,7 @@ static id _Nullable DecodeAttributeValueForWiFiNetworkDiagnosticsCluster( if (cppValue.IsNull()) { value = nil; } else { - value = [NSData dataWithBytes:cppValue.Value().data() length:cppValue.Value().size()]; + value = AsData(cppValue.Value()); } return value; } @@ -7133,7 +7259,12 @@ static id _Nullable DecodeAttributeValueForBridgedDeviceBasicInformationCluster( return nil; } NSString * _Nonnull value; - value = [[NSString alloc] initWithBytes:cppValue.data() length:cppValue.size() encoding:NSUTF8StringEncoding]; + value = AsString(cppValue); + if (value == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + *aError = err; + return nil; + } return value; } case Attributes::VendorID::Id: { @@ -7155,7 +7286,12 @@ static id _Nullable DecodeAttributeValueForBridgedDeviceBasicInformationCluster( return nil; } NSString * _Nonnull value; - value = [[NSString alloc] initWithBytes:cppValue.data() length:cppValue.size() encoding:NSUTF8StringEncoding]; + value = AsString(cppValue); + if (value == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + *aError = err; + return nil; + } return value; } case Attributes::NodeLabel::Id: { @@ -7166,7 +7302,12 @@ static id _Nullable DecodeAttributeValueForBridgedDeviceBasicInformationCluster( return nil; } NSString * _Nonnull value; - value = [[NSString alloc] initWithBytes:cppValue.data() length:cppValue.size() encoding:NSUTF8StringEncoding]; + value = AsString(cppValue); + if (value == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + *aError = err; + return nil; + } return value; } case Attributes::HardwareVersion::Id: { @@ -7188,7 +7329,12 @@ static id _Nullable DecodeAttributeValueForBridgedDeviceBasicInformationCluster( return nil; } NSString * _Nonnull value; - value = [[NSString alloc] initWithBytes:cppValue.data() length:cppValue.size() encoding:NSUTF8StringEncoding]; + value = AsString(cppValue); + if (value == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + *aError = err; + return nil; + } return value; } case Attributes::SoftwareVersion::Id: { @@ -7210,7 +7356,12 @@ static id _Nullable DecodeAttributeValueForBridgedDeviceBasicInformationCluster( return nil; } NSString * _Nonnull value; - value = [[NSString alloc] initWithBytes:cppValue.data() length:cppValue.size() encoding:NSUTF8StringEncoding]; + value = AsString(cppValue); + if (value == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + *aError = err; + return nil; + } return value; } case Attributes::ManufacturingDate::Id: { @@ -7221,7 +7372,12 @@ static id _Nullable DecodeAttributeValueForBridgedDeviceBasicInformationCluster( return nil; } NSString * _Nonnull value; - value = [[NSString alloc] initWithBytes:cppValue.data() length:cppValue.size() encoding:NSUTF8StringEncoding]; + value = AsString(cppValue); + if (value == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + *aError = err; + return nil; + } return value; } case Attributes::PartNumber::Id: { @@ -7232,7 +7388,12 @@ static id _Nullable DecodeAttributeValueForBridgedDeviceBasicInformationCluster( return nil; } NSString * _Nonnull value; - value = [[NSString alloc] initWithBytes:cppValue.data() length:cppValue.size() encoding:NSUTF8StringEncoding]; + value = AsString(cppValue); + if (value == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + *aError = err; + return nil; + } return value; } case Attributes::ProductURL::Id: { @@ -7243,7 +7404,12 @@ static id _Nullable DecodeAttributeValueForBridgedDeviceBasicInformationCluster( return nil; } NSString * _Nonnull value; - value = [[NSString alloc] initWithBytes:cppValue.data() length:cppValue.size() encoding:NSUTF8StringEncoding]; + value = AsString(cppValue); + if (value == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + *aError = err; + return nil; + } return value; } case Attributes::ProductLabel::Id: { @@ -7254,7 +7420,12 @@ static id _Nullable DecodeAttributeValueForBridgedDeviceBasicInformationCluster( return nil; } NSString * _Nonnull value; - value = [[NSString alloc] initWithBytes:cppValue.data() length:cppValue.size() encoding:NSUTF8StringEncoding]; + value = AsString(cppValue); + if (value == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + *aError = err; + return nil; + } return value; } case Attributes::SerialNumber::Id: { @@ -7265,7 +7436,12 @@ static id _Nullable DecodeAttributeValueForBridgedDeviceBasicInformationCluster( return nil; } NSString * _Nonnull value; - value = [[NSString alloc] initWithBytes:cppValue.data() length:cppValue.size() encoding:NSUTF8StringEncoding]; + value = AsString(cppValue); + if (value == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + *aError = err; + return nil; + } return value; } case Attributes::Reachable::Id: { @@ -7287,7 +7463,12 @@ static id _Nullable DecodeAttributeValueForBridgedDeviceBasicInformationCluster( return nil; } NSString * _Nonnull value; - value = [[NSString alloc] initWithBytes:cppValue.data() length:cppValue.size() encoding:NSUTF8StringEncoding]; + value = AsString(cppValue); + if (value == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + *aError = err; + return nil; + } return value; } case Attributes::ProductAppearance::Id: { @@ -7812,11 +7993,11 @@ static id _Nullable DecodeAttributeValueForOperationalCredentialsCluster( auto & entry_0 = iter_0.GetValue(); MTROperationalCredentialsClusterNOCStruct * newElement_0; newElement_0 = [MTROperationalCredentialsClusterNOCStruct new]; - newElement_0.noc = [NSData dataWithBytes:entry_0.noc.data() length:entry_0.noc.size()]; + newElement_0.noc = AsData(entry_0.noc); if (entry_0.icac.IsNull()) { newElement_0.icac = nil; } else { - newElement_0.icac = [NSData dataWithBytes:entry_0.icac.Value().data() length:entry_0.icac.Value().size()]; + newElement_0.icac = AsData(entry_0.icac.Value()); } newElement_0.fabricIndex = [NSNumber numberWithUnsignedChar:entry_0.fabricIndex]; [array_0 addObject:newElement_0]; @@ -7845,14 +8026,16 @@ static id _Nullable DecodeAttributeValueForOperationalCredentialsCluster( auto & entry_0 = iter_0.GetValue(); MTROperationalCredentialsClusterFabricDescriptorStruct * newElement_0; newElement_0 = [MTROperationalCredentialsClusterFabricDescriptorStruct new]; - newElement_0.rootPublicKey = [NSData dataWithBytes:entry_0.rootPublicKey.data() - length:entry_0.rootPublicKey.size()]; + newElement_0.rootPublicKey = AsData(entry_0.rootPublicKey); newElement_0.vendorID = [NSNumber numberWithUnsignedShort:chip::to_underlying(entry_0.vendorID)]; newElement_0.fabricID = [NSNumber numberWithUnsignedLongLong:entry_0.fabricID]; newElement_0.nodeID = [NSNumber numberWithUnsignedLongLong:entry_0.nodeID]; - newElement_0.label = [[NSString alloc] initWithBytes:entry_0.label.data() - length:entry_0.label.size() - encoding:NSUTF8StringEncoding]; + newElement_0.label = AsString(entry_0.label); + if (newElement_0.label == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + *aError = err; + return nil; + } newElement_0.fabricIndex = [NSNumber numberWithUnsignedChar:entry_0.fabricIndex]; [array_0 addObject:newElement_0]; } @@ -7901,7 +8084,7 @@ static id _Nullable DecodeAttributeValueForOperationalCredentialsCluster( while (iter_0.Next()) { auto & entry_0 = iter_0.GetValue(); NSData * newElement_0; - newElement_0 = [NSData dataWithBytes:entry_0.data() length:entry_0.size()]; + newElement_0 = AsData(entry_0); [array_0 addObject:newElement_0]; } CHIP_ERROR err = iter_0.GetStatus(); @@ -8125,9 +8308,12 @@ static id _Nullable DecodeAttributeValueForGroupKeyManagementCluster( newElement_0.endpoints = array_2; } if (entry_0.groupName.HasValue()) { - newElement_0.groupName = [[NSString alloc] initWithBytes:entry_0.groupName.Value().data() - length:entry_0.groupName.Value().size() - encoding:NSUTF8StringEncoding]; + newElement_0.groupName = AsString(entry_0.groupName.Value()); + if (newElement_0.groupName == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + *aError = err; + return nil; + } } else { newElement_0.groupName = nil; } @@ -8319,12 +8505,18 @@ static id _Nullable DecodeAttributeValueForFixedLabelCluster( auto & entry_0 = iter_0.GetValue(); MTRFixedLabelClusterLabelStruct * newElement_0; newElement_0 = [MTRFixedLabelClusterLabelStruct new]; - newElement_0.label = [[NSString alloc] initWithBytes:entry_0.label.data() - length:entry_0.label.size() - encoding:NSUTF8StringEncoding]; - newElement_0.value = [[NSString alloc] initWithBytes:entry_0.value.data() - length:entry_0.value.size() - encoding:NSUTF8StringEncoding]; + newElement_0.label = AsString(entry_0.label); + if (newElement_0.label == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + *aError = err; + return nil; + } + newElement_0.value = AsString(entry_0.value); + if (newElement_0.value == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + *aError = err; + return nil; + } [array_0 addObject:newElement_0]; } CHIP_ERROR err = iter_0.GetStatus(); @@ -8489,12 +8681,18 @@ static id _Nullable DecodeAttributeValueForUserLabelCluster(AttributeId aAttribu auto & entry_0 = iter_0.GetValue(); MTRUserLabelClusterLabelStruct * newElement_0; newElement_0 = [MTRUserLabelClusterLabelStruct new]; - newElement_0.label = [[NSString alloc] initWithBytes:entry_0.label.data() - length:entry_0.label.size() - encoding:NSUTF8StringEncoding]; - newElement_0.value = [[NSString alloc] initWithBytes:entry_0.value.data() - length:entry_0.value.size() - encoding:NSUTF8StringEncoding]; + newElement_0.label = AsString(entry_0.label); + if (newElement_0.label == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + *aError = err; + return nil; + } + newElement_0.value = AsString(entry_0.value); + if (newElement_0.value == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + *aError = err; + return nil; + } [array_0 addObject:newElement_0]; } CHIP_ERROR err = iter_0.GetStatus(); @@ -8803,7 +9001,12 @@ static id _Nullable DecodeAttributeValueForModeSelectCluster( return nil; } NSString * _Nonnull value; - value = [[NSString alloc] initWithBytes:cppValue.data() length:cppValue.size() encoding:NSUTF8StringEncoding]; + value = AsString(cppValue); + if (value == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + *aError = err; + return nil; + } return value; } case Attributes::StandardNamespace::Id: { @@ -8836,9 +9039,12 @@ static id _Nullable DecodeAttributeValueForModeSelectCluster( auto & entry_0 = iter_0.GetValue(); MTRModeSelectClusterModeOptionStruct * newElement_0; newElement_0 = [MTRModeSelectClusterModeOptionStruct new]; - newElement_0.label = [[NSString alloc] initWithBytes:entry_0.label.data() - length:entry_0.label.size() - encoding:NSUTF8StringEncoding]; + newElement_0.label = AsString(entry_0.label); + if (newElement_0.label == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + *aError = err; + return nil; + } newElement_0.mode = [NSNumber numberWithUnsignedChar:entry_0.mode]; { // Scope for our temporary variables auto * array_2 = [NSMutableArray new]; @@ -9119,9 +9325,12 @@ static id _Nullable DecodeAttributeValueForTemperatureControlCluster( auto & entry_0 = iter_0.GetValue(); MTRTemperatureControlClusterTemperatureLevelStruct * newElement_0; newElement_0 = [MTRTemperatureControlClusterTemperatureLevelStruct new]; - newElement_0.label = [[NSString alloc] initWithBytes:entry_0.label.data() - length:entry_0.label.size() - encoding:NSUTF8StringEncoding]; + newElement_0.label = AsString(entry_0.label); + if (newElement_0.label == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + *aError = err; + return nil; + } newElement_0.temperatureLevel = [NSNumber numberWithUnsignedChar:entry_0.temperatureLevel]; [array_0 addObject:newElement_0]; } @@ -12286,7 +12495,12 @@ static id _Nullable DecodeAttributeValueForDoorLockCluster(AttributeId aAttribut return nil; } NSString * _Nonnull value; - value = [[NSString alloc] initWithBytes:cppValue.data() length:cppValue.size() encoding:NSUTF8StringEncoding]; + value = AsString(cppValue); + if (value == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + *aError = err; + return nil; + } return value; } case Attributes::LEDSettings::Id: { @@ -14966,7 +15180,12 @@ static id _Nullable DecodeAttributeValueForColorControlCluster( return nil; } NSString * _Nonnull value; - value = [[NSString alloc] initWithBytes:cppValue.data() length:cppValue.size() encoding:NSUTF8StringEncoding]; + value = AsString(cppValue); + if (value == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + *aError = err; + return nil; + } return value; } case Attributes::ColorTemperatureMireds::Id: { @@ -15751,7 +15970,12 @@ static id _Nullable DecodeAttributeValueForBallastConfigurationCluster( return nil; } NSString * _Nonnull value; - value = [[NSString alloc] initWithBytes:cppValue.data() length:cppValue.size() encoding:NSUTF8StringEncoding]; + value = AsString(cppValue); + if (value == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + *aError = err; + return nil; + } return value; } case Attributes::LampManufacturer::Id: { @@ -15762,7 +15986,12 @@ static id _Nullable DecodeAttributeValueForBallastConfigurationCluster( return nil; } NSString * _Nonnull value; - value = [[NSString alloc] initWithBytes:cppValue.data() length:cppValue.size() encoding:NSUTF8StringEncoding]; + value = AsString(cppValue); + if (value == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + *aError = err; + return nil; + } return value; } case Attributes::LampRatedHours::Id: { @@ -27375,7 +27604,12 @@ static id _Nullable DecodeAttributeValueForWakeOnLANCluster(AttributeId aAttribu return nil; } NSString * _Nonnull value; - value = [[NSString alloc] initWithBytes:cppValue.data() length:cppValue.size() encoding:NSUTF8StringEncoding]; + value = AsString(cppValue); + if (value == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + *aError = err; + return nil; + } return value; } case Attributes::GeneratedCommandList::Id: { @@ -27534,23 +27768,32 @@ static id _Nullable DecodeAttributeValueForChannelCluster(AttributeId aAttribute newElement_0.majorNumber = [NSNumber numberWithUnsignedShort:entry_0.majorNumber]; newElement_0.minorNumber = [NSNumber numberWithUnsignedShort:entry_0.minorNumber]; if (entry_0.name.HasValue()) { - newElement_0.name = [[NSString alloc] initWithBytes:entry_0.name.Value().data() - length:entry_0.name.Value().size() - encoding:NSUTF8StringEncoding]; + newElement_0.name = AsString(entry_0.name.Value()); + if (newElement_0.name == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + *aError = err; + return nil; + } } else { newElement_0.name = nil; } if (entry_0.callSign.HasValue()) { - newElement_0.callSign = [[NSString alloc] initWithBytes:entry_0.callSign.Value().data() - length:entry_0.callSign.Value().size() - encoding:NSUTF8StringEncoding]; + newElement_0.callSign = AsString(entry_0.callSign.Value()); + if (newElement_0.callSign == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + *aError = err; + return nil; + } } else { newElement_0.callSign = nil; } if (entry_0.affiliateCallSign.HasValue()) { - newElement_0.affiliateCallSign = [[NSString alloc] initWithBytes:entry_0.affiliateCallSign.Value().data() - length:entry_0.affiliateCallSign.Value().size() - encoding:NSUTF8StringEncoding]; + newElement_0.affiliateCallSign = AsString(entry_0.affiliateCallSign.Value()); + if (newElement_0.affiliateCallSign == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + *aError = err; + return nil; + } } else { newElement_0.affiliateCallSign = nil; } @@ -27577,20 +27820,29 @@ static id _Nullable DecodeAttributeValueForChannelCluster(AttributeId aAttribute value = nil; } else { value = [MTRChannelClusterLineupInfoStruct new]; - value.operatorName = [[NSString alloc] initWithBytes:cppValue.Value().operatorName.data() - length:cppValue.Value().operatorName.size() - encoding:NSUTF8StringEncoding]; + value.operatorName = AsString(cppValue.Value().operatorName); + if (value.operatorName == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + *aError = err; + return nil; + } if (cppValue.Value().lineupName.HasValue()) { - value.lineupName = [[NSString alloc] initWithBytes:cppValue.Value().lineupName.Value().data() - length:cppValue.Value().lineupName.Value().size() - encoding:NSUTF8StringEncoding]; + value.lineupName = AsString(cppValue.Value().lineupName.Value()); + if (value.lineupName == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + *aError = err; + return nil; + } } else { value.lineupName = nil; } if (cppValue.Value().postalCode.HasValue()) { - value.postalCode = [[NSString alloc] initWithBytes:cppValue.Value().postalCode.Value().data() - length:cppValue.Value().postalCode.Value().size() - encoding:NSUTF8StringEncoding]; + value.postalCode = AsString(cppValue.Value().postalCode.Value()); + if (value.postalCode == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + *aError = err; + return nil; + } } else { value.postalCode = nil; } @@ -27613,23 +27865,32 @@ static id _Nullable DecodeAttributeValueForChannelCluster(AttributeId aAttribute value.majorNumber = [NSNumber numberWithUnsignedShort:cppValue.Value().majorNumber]; value.minorNumber = [NSNumber numberWithUnsignedShort:cppValue.Value().minorNumber]; if (cppValue.Value().name.HasValue()) { - value.name = [[NSString alloc] initWithBytes:cppValue.Value().name.Value().data() - length:cppValue.Value().name.Value().size() - encoding:NSUTF8StringEncoding]; + value.name = AsString(cppValue.Value().name.Value()); + if (value.name == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + *aError = err; + return nil; + } } else { value.name = nil; } if (cppValue.Value().callSign.HasValue()) { - value.callSign = [[NSString alloc] initWithBytes:cppValue.Value().callSign.Value().data() - length:cppValue.Value().callSign.Value().size() - encoding:NSUTF8StringEncoding]; + value.callSign = AsString(cppValue.Value().callSign.Value()); + if (value.callSign == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + *aError = err; + return nil; + } } else { value.callSign = nil; } if (cppValue.Value().affiliateCallSign.HasValue()) { - value.affiliateCallSign = [[NSString alloc] initWithBytes:cppValue.Value().affiliateCallSign.Value().data() - length:cppValue.Value().affiliateCallSign.Value().size() - encoding:NSUTF8StringEncoding]; + value.affiliateCallSign = AsString(cppValue.Value().affiliateCallSign.Value()); + if (value.affiliateCallSign == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + *aError = err; + return nil; + } } else { value.affiliateCallSign = nil; } @@ -27791,9 +28052,12 @@ static id _Nullable DecodeAttributeValueForTargetNavigatorCluster( MTRTargetNavigatorClusterTargetInfoStruct * newElement_0; newElement_0 = [MTRTargetNavigatorClusterTargetInfoStruct new]; newElement_0.identifier = [NSNumber numberWithUnsignedChar:entry_0.identifier]; - newElement_0.name = [[NSString alloc] initWithBytes:entry_0.name.data() - length:entry_0.name.size() - encoding:NSUTF8StringEncoding]; + newElement_0.name = AsString(entry_0.name); + if (newElement_0.name == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + *aError = err; + return nil; + } [array_0 addObject:newElement_0]; } CHIP_ERROR err = iter_0.GetStatus(); @@ -28214,12 +28478,18 @@ static id _Nullable DecodeAttributeValueForMediaInputCluster( newElement_0 = [MTRMediaInputClusterInputInfoStruct new]; newElement_0.index = [NSNumber numberWithUnsignedChar:entry_0.index]; newElement_0.inputType = [NSNumber numberWithUnsignedChar:chip::to_underlying(entry_0.inputType)]; - newElement_0.name = [[NSString alloc] initWithBytes:entry_0.name.data() - length:entry_0.name.size() - encoding:NSUTF8StringEncoding]; - newElement_0.descriptionString = [[NSString alloc] initWithBytes:entry_0.description.data() - length:entry_0.description.size() - encoding:NSUTF8StringEncoding]; + newElement_0.name = AsString(entry_0.name); + if (newElement_0.name == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + *aError = err; + return nil; + } + newElement_0.descriptionString = AsString(entry_0.description); + if (newElement_0.descriptionString == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + *aError = err; + return nil; + } [array_0 addObject:newElement_0]; } CHIP_ERROR err = iter_0.GetStatus(); @@ -28672,7 +28942,12 @@ static id _Nullable DecodeAttributeValueForContentLauncherCluster( while (iter_0.Next()) { auto & entry_0 = iter_0.GetValue(); NSString * newElement_0; - newElement_0 = [[NSString alloc] initWithBytes:entry_0.data() length:entry_0.size() encoding:NSUTF8StringEncoding]; + newElement_0 = AsString(entry_0); + if (newElement_0 == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + *aError = err; + return nil; + } [array_0 addObject:newElement_0]; } CHIP_ERROR err = iter_0.GetStatus(); @@ -28851,9 +29126,12 @@ static id _Nullable DecodeAttributeValueForAudioOutputCluster( newElement_0 = [MTRAudioOutputClusterOutputInfoStruct new]; newElement_0.index = [NSNumber numberWithUnsignedChar:entry_0.index]; newElement_0.outputType = [NSNumber numberWithUnsignedChar:chip::to_underlying(entry_0.outputType)]; - newElement_0.name = [[NSString alloc] initWithBytes:entry_0.name.data() - length:entry_0.name.size() - encoding:NSUTF8StringEncoding]; + newElement_0.name = AsString(entry_0.name); + if (newElement_0.name == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + *aError = err; + return nil; + } [array_0 addObject:newElement_0]; } CHIP_ERROR err = iter_0.GetStatus(); @@ -29055,9 +29333,12 @@ static id _Nullable DecodeAttributeValueForApplicationLauncherCluster( value = [MTRApplicationLauncherClusterApplicationEPStruct new]; value.application = [MTRApplicationLauncherClusterApplicationStruct new]; value.application.catalogVendorID = [NSNumber numberWithUnsignedShort:cppValue.Value().application.catalogVendorID]; - value.application.applicationID = [[NSString alloc] initWithBytes:cppValue.Value().application.applicationID.data() - length:cppValue.Value().application.applicationID.size() - encoding:NSUTF8StringEncoding]; + value.application.applicationID = AsString(cppValue.Value().application.applicationID); + if (value.application.applicationID == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + *aError = err; + return nil; + } if (cppValue.Value().endpoint.HasValue()) { value.endpoint = [NSNumber numberWithUnsignedShort:cppValue.Value().endpoint.Value()]; } else { @@ -29213,7 +29494,12 @@ static id _Nullable DecodeAttributeValueForApplicationBasicCluster( return nil; } NSString * _Nonnull value; - value = [[NSString alloc] initWithBytes:cppValue.data() length:cppValue.size() encoding:NSUTF8StringEncoding]; + value = AsString(cppValue); + if (value == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + *aError = err; + return nil; + } return value; } case Attributes::VendorID::Id: { @@ -29235,7 +29521,12 @@ static id _Nullable DecodeAttributeValueForApplicationBasicCluster( return nil; } NSString * _Nonnull value; - value = [[NSString alloc] initWithBytes:cppValue.data() length:cppValue.size() encoding:NSUTF8StringEncoding]; + value = AsString(cppValue); + if (value == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + *aError = err; + return nil; + } return value; } case Attributes::ProductID::Id: { @@ -29259,9 +29550,12 @@ static id _Nullable DecodeAttributeValueForApplicationBasicCluster( MTRApplicationBasicClusterApplicationStruct * _Nonnull value; value = [MTRApplicationBasicClusterApplicationStruct new]; value.catalogVendorID = [NSNumber numberWithUnsignedShort:cppValue.catalogVendorID]; - value.applicationID = [[NSString alloc] initWithBytes:cppValue.applicationID.data() - length:cppValue.applicationID.size() - encoding:NSUTF8StringEncoding]; + value.applicationID = AsString(cppValue.applicationID); + if (value.applicationID == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + *aError = err; + return nil; + } return value; } case Attributes::Status::Id: { @@ -29283,7 +29577,12 @@ static id _Nullable DecodeAttributeValueForApplicationBasicCluster( return nil; } NSString * _Nonnull value; - value = [[NSString alloc] initWithBytes:cppValue.data() length:cppValue.size() encoding:NSUTF8StringEncoding]; + value = AsString(cppValue); + if (value == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + *aError = err; + return nil; + } return value; } case Attributes::AllowedVendorList::Id: { @@ -31420,7 +31719,7 @@ static id _Nullable DecodeAttributeValueForUnitTestingCluster( return nil; } NSData * _Nonnull value; - value = [NSData dataWithBytes:cppValue.data() length:cppValue.size()]; + value = AsData(cppValue); return value; } case Attributes::ListInt8u::Id: { @@ -31463,7 +31762,7 @@ static id _Nullable DecodeAttributeValueForUnitTestingCluster( while (iter_0.Next()) { auto & entry_0 = iter_0.GetValue(); NSData * newElement_0; - newElement_0 = [NSData dataWithBytes:entry_0.data() length:entry_0.size()]; + newElement_0 = AsData(entry_0); [array_0 addObject:newElement_0]; } CHIP_ERROR err = iter_0.GetStatus(); @@ -31491,7 +31790,7 @@ static id _Nullable DecodeAttributeValueForUnitTestingCluster( MTRUnitTestingClusterTestListStructOctet * newElement_0; newElement_0 = [MTRUnitTestingClusterTestListStructOctet new]; newElement_0.member1 = [NSNumber numberWithUnsignedLongLong:entry_0.member1]; - newElement_0.member2 = [NSData dataWithBytes:entry_0.member2.data() length:entry_0.member2.size()]; + newElement_0.member2 = AsData(entry_0.member2); [array_0 addObject:newElement_0]; } CHIP_ERROR err = iter_0.GetStatus(); @@ -31511,7 +31810,7 @@ static id _Nullable DecodeAttributeValueForUnitTestingCluster( return nil; } NSData * _Nonnull value; - value = [NSData dataWithBytes:cppValue.data() length:cppValue.size()]; + value = AsData(cppValue); return value; } case Attributes::CharString::Id: { @@ -31522,7 +31821,12 @@ static id _Nullable DecodeAttributeValueForUnitTestingCluster( return nil; } NSString * _Nonnull value; - value = [[NSString alloc] initWithBytes:cppValue.data() length:cppValue.size() encoding:NSUTF8StringEncoding]; + value = AsString(cppValue); + if (value == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + *aError = err; + return nil; + } return value; } case Attributes::LongCharString::Id: { @@ -31533,7 +31837,12 @@ static id _Nullable DecodeAttributeValueForUnitTestingCluster( return nil; } NSString * _Nonnull value; - value = [[NSString alloc] initWithBytes:cppValue.data() length:cppValue.size() encoding:NSUTF8StringEncoding]; + value = AsString(cppValue); + if (value == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + *aError = err; + return nil; + } return value; } case Attributes::EpochUs::Id: { @@ -31607,14 +31916,20 @@ static id _Nullable DecodeAttributeValueForUnitTestingCluster( if (entry_0.nullableString.IsNull()) { newElement_0.nullableString = nil; } else { - newElement_0.nullableString = [[NSString alloc] initWithBytes:entry_0.nullableString.Value().data() - length:entry_0.nullableString.Value().size() - encoding:NSUTF8StringEncoding]; + newElement_0.nullableString = AsString(entry_0.nullableString.Value()); + if (newElement_0.nullableString == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + *aError = err; + return nil; + } } if (entry_0.optionalString.HasValue()) { - newElement_0.optionalString = [[NSString alloc] initWithBytes:entry_0.optionalString.Value().data() - length:entry_0.optionalString.Value().size() - encoding:NSUTF8StringEncoding]; + newElement_0.optionalString = AsString(entry_0.optionalString.Value()); + if (newElement_0.optionalString == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + *aError = err; + return nil; + } } else { newElement_0.optionalString = nil; } @@ -31622,10 +31937,12 @@ static id _Nullable DecodeAttributeValueForUnitTestingCluster( if (entry_0.nullableOptionalString.Value().IsNull()) { newElement_0.nullableOptionalString = nil; } else { - newElement_0.nullableOptionalString = - [[NSString alloc] initWithBytes:entry_0.nullableOptionalString.Value().Value().data() - length:entry_0.nullableOptionalString.Value().Value().size() - encoding:NSUTF8StringEncoding]; + newElement_0.nullableOptionalString = AsString(entry_0.nullableOptionalString.Value().Value()); + if (newElement_0.nullableOptionalString == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + *aError = err; + return nil; + } } } else { newElement_0.nullableOptionalString = nil; @@ -31638,11 +31955,13 @@ static id _Nullable DecodeAttributeValueForUnitTestingCluster( newElement_0.nullableStruct.b = [NSNumber numberWithBool:entry_0.nullableStruct.Value().b]; newElement_0.nullableStruct.c = [NSNumber numberWithUnsignedChar:chip::to_underlying(entry_0.nullableStruct.Value().c)]; - newElement_0.nullableStruct.d = [NSData dataWithBytes:entry_0.nullableStruct.Value().d.data() - length:entry_0.nullableStruct.Value().d.size()]; - newElement_0.nullableStruct.e = [[NSString alloc] initWithBytes:entry_0.nullableStruct.Value().e.data() - length:entry_0.nullableStruct.Value().e.size() - encoding:NSUTF8StringEncoding]; + newElement_0.nullableStruct.d = AsData(entry_0.nullableStruct.Value().d); + newElement_0.nullableStruct.e = AsString(entry_0.nullableStruct.Value().e); + if (newElement_0.nullableStruct.e == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + *aError = err; + return nil; + } newElement_0.nullableStruct.f = [NSNumber numberWithUnsignedChar:entry_0.nullableStruct.Value().f.Raw()]; newElement_0.nullableStruct.g = [NSNumber numberWithFloat:entry_0.nullableStruct.Value().g]; newElement_0.nullableStruct.h = [NSNumber numberWithDouble:entry_0.nullableStruct.Value().h]; @@ -31653,11 +31972,13 @@ static id _Nullable DecodeAttributeValueForUnitTestingCluster( newElement_0.optionalStruct.b = [NSNumber numberWithBool:entry_0.optionalStruct.Value().b]; newElement_0.optionalStruct.c = [NSNumber numberWithUnsignedChar:chip::to_underlying(entry_0.optionalStruct.Value().c)]; - newElement_0.optionalStruct.d = [NSData dataWithBytes:entry_0.optionalStruct.Value().d.data() - length:entry_0.optionalStruct.Value().d.size()]; - newElement_0.optionalStruct.e = [[NSString alloc] initWithBytes:entry_0.optionalStruct.Value().e.data() - length:entry_0.optionalStruct.Value().e.size() - encoding:NSUTF8StringEncoding]; + newElement_0.optionalStruct.d = AsData(entry_0.optionalStruct.Value().d); + newElement_0.optionalStruct.e = AsString(entry_0.optionalStruct.Value().e); + if (newElement_0.optionalStruct.e == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + *aError = err; + return nil; + } newElement_0.optionalStruct.f = [NSNumber numberWithUnsignedChar:entry_0.optionalStruct.Value().f.Raw()]; newElement_0.optionalStruct.g = [NSNumber numberWithFloat:entry_0.optionalStruct.Value().g]; newElement_0.optionalStruct.h = [NSNumber numberWithDouble:entry_0.optionalStruct.Value().h]; @@ -31675,13 +31996,13 @@ static id _Nullable DecodeAttributeValueForUnitTestingCluster( [NSNumber numberWithBool:entry_0.nullableOptionalStruct.Value().Value().b]; newElement_0.nullableOptionalStruct.c = [NSNumber numberWithUnsignedChar:chip::to_underlying(entry_0.nullableOptionalStruct.Value().Value().c)]; - newElement_0.nullableOptionalStruct.d = - [NSData dataWithBytes:entry_0.nullableOptionalStruct.Value().Value().d.data() - length:entry_0.nullableOptionalStruct.Value().Value().d.size()]; - newElement_0.nullableOptionalStruct.e = - [[NSString alloc] initWithBytes:entry_0.nullableOptionalStruct.Value().Value().e.data() - length:entry_0.nullableOptionalStruct.Value().Value().e.size() - encoding:NSUTF8StringEncoding]; + newElement_0.nullableOptionalStruct.d = AsData(entry_0.nullableOptionalStruct.Value().Value().d); + newElement_0.nullableOptionalStruct.e = AsString(entry_0.nullableOptionalStruct.Value().Value().e); + if (newElement_0.nullableOptionalStruct.e == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + *aError = err; + return nil; + } newElement_0.nullableOptionalStruct.f = [NSNumber numberWithUnsignedChar:entry_0.nullableOptionalStruct.Value().Value().f.Raw()]; newElement_0.nullableOptionalStruct.g = @@ -31790,8 +32111,13 @@ static id _Nullable DecodeAttributeValueForUnitTestingCluster( value.a = [NSNumber numberWithUnsignedChar:cppValue.a]; value.b = [NSNumber numberWithBool:cppValue.b]; value.c = [NSNumber numberWithUnsignedChar:chip::to_underlying(cppValue.c)]; - value.d = [NSData dataWithBytes:cppValue.d.data() length:cppValue.d.size()]; - value.e = [[NSString alloc] initWithBytes:cppValue.e.data() length:cppValue.e.size() encoding:NSUTF8StringEncoding]; + value.d = AsData(cppValue.d); + value.e = AsString(cppValue.e); + if (value.e == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + *aError = err; + return nil; + } value.f = [NSNumber numberWithUnsignedChar:cppValue.f.Raw()]; value.g = [NSNumber numberWithFloat:cppValue.g]; value.h = [NSNumber numberWithDouble:cppValue.h]; @@ -31855,7 +32181,7 @@ static id _Nullable DecodeAttributeValueForUnitTestingCluster( while (iter_0.Next()) { auto & entry_0 = iter_0.GetValue(); NSData * newElement_0; - newElement_0 = [NSData dataWithBytes:entry_0.data() length:entry_0.size()]; + newElement_0 = AsData(entry_0); [array_0 addObject:newElement_0]; } CHIP_ERROR err = iter_0.GetStatus(); @@ -31905,19 +32231,24 @@ static id _Nullable DecodeAttributeValueForUnitTestingCluster( } else { newElement_0.nullableOptionalFabricSensitiveInt8u = nil; } - newElement_0.fabricSensitiveCharString = [[NSString alloc] initWithBytes:entry_0.fabricSensitiveCharString.data() - length:entry_0.fabricSensitiveCharString.size() - encoding:NSUTF8StringEncoding]; + newElement_0.fabricSensitiveCharString = AsString(entry_0.fabricSensitiveCharString); + if (newElement_0.fabricSensitiveCharString == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + *aError = err; + return nil; + } newElement_0.fabricSensitiveStruct = [MTRUnitTestingClusterSimpleStruct new]; newElement_0.fabricSensitiveStruct.a = [NSNumber numberWithUnsignedChar:entry_0.fabricSensitiveStruct.a]; newElement_0.fabricSensitiveStruct.b = [NSNumber numberWithBool:entry_0.fabricSensitiveStruct.b]; newElement_0.fabricSensitiveStruct.c = [NSNumber numberWithUnsignedChar:chip::to_underlying(entry_0.fabricSensitiveStruct.c)]; - newElement_0.fabricSensitiveStruct.d = [NSData dataWithBytes:entry_0.fabricSensitiveStruct.d.data() - length:entry_0.fabricSensitiveStruct.d.size()]; - newElement_0.fabricSensitiveStruct.e = [[NSString alloc] initWithBytes:entry_0.fabricSensitiveStruct.e.data() - length:entry_0.fabricSensitiveStruct.e.size() - encoding:NSUTF8StringEncoding]; + newElement_0.fabricSensitiveStruct.d = AsData(entry_0.fabricSensitiveStruct.d); + newElement_0.fabricSensitiveStruct.e = AsString(entry_0.fabricSensitiveStruct.e); + if (newElement_0.fabricSensitiveStruct.e == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + *aError = err; + return nil; + } newElement_0.fabricSensitiveStruct.f = [NSNumber numberWithUnsignedChar:entry_0.fabricSensitiveStruct.f.Raw()]; newElement_0.fabricSensitiveStruct.g = [NSNumber numberWithFloat:entry_0.fabricSensitiveStruct.g]; newElement_0.fabricSensitiveStruct.h = [NSNumber numberWithDouble:entry_0.fabricSensitiveStruct.h]; @@ -32379,7 +32710,7 @@ static id _Nullable DecodeAttributeValueForUnitTestingCluster( if (cppValue.IsNull()) { value = nil; } else { - value = [NSData dataWithBytes:cppValue.Value().data() length:cppValue.Value().size()]; + value = AsData(cppValue.Value()); } return value; } @@ -32394,9 +32725,12 @@ static id _Nullable DecodeAttributeValueForUnitTestingCluster( if (cppValue.IsNull()) { value = nil; } else { - value = [[NSString alloc] initWithBytes:cppValue.Value().data() - length:cppValue.Value().size() - encoding:NSUTF8StringEncoding]; + value = AsString(cppValue.Value()); + if (value == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + *aError = err; + return nil; + } } return value; } @@ -32430,10 +32764,13 @@ static id _Nullable DecodeAttributeValueForUnitTestingCluster( value.a = [NSNumber numberWithUnsignedChar:cppValue.Value().a]; value.b = [NSNumber numberWithBool:cppValue.Value().b]; value.c = [NSNumber numberWithUnsignedChar:chip::to_underlying(cppValue.Value().c)]; - value.d = [NSData dataWithBytes:cppValue.Value().d.data() length:cppValue.Value().d.size()]; - value.e = [[NSString alloc] initWithBytes:cppValue.Value().e.data() - length:cppValue.Value().e.size() - encoding:NSUTF8StringEncoding]; + value.d = AsData(cppValue.Value().d); + value.e = AsString(cppValue.Value().e); + if (value.e == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + *aError = err; + return nil; + } value.f = [NSNumber numberWithUnsignedChar:cppValue.Value().f.Raw()]; value.g = [NSNumber numberWithFloat:cppValue.Value().g]; value.h = [NSNumber numberWithDouble:cppValue.Value().h]; diff --git a/src/darwin/Framework/CHIP/zap-generated/MTRCallbackBridge.mm b/src/darwin/Framework/CHIP/zap-generated/MTRCallbackBridge.mm index c830740e0e732a..c7eb03493f64d9 100644 --- a/src/darwin/Framework/CHIP/zap-generated/MTRCallbackBridge.mm +++ b/src/darwin/Framework/CHIP/zap-generated/MTRCallbackBridge.mm @@ -19,6 +19,8 @@ #import "MTRCommandPayloadsObjc.h" #import "MTRCommandPayloads_Internal.h" #import "MTRStructsObjc.h" +#import "NSDataSpanConversion.h" +#import "NSStringSpanConversion.h" #include @@ -32,7 +34,7 @@ void MTROctetStringAttributeCallbackBridge::OnSuccessFn(void * context, chip::ByteSpan value) { NSData * _Nonnull objCValue; - objCValue = [NSData dataWithBytes:value.data() length:value.size()]; + objCValue = AsData(value); DispatchSuccess(context, objCValue); }; @@ -58,7 +60,7 @@ if (value.IsNull()) { objCValue = nil; } else { - objCValue = [NSData dataWithBytes:value.Value().data() length:value.Value().size()]; + objCValue = AsData(value.Value()); } DispatchSuccess(context, objCValue); }; @@ -81,7 +83,12 @@ void MTRCharStringAttributeCallbackBridge::OnSuccessFn(void * context, chip::CharSpan value) { NSString * _Nonnull objCValue; - objCValue = [[NSString alloc] initWithBytes:value.data() length:value.size() encoding:NSUTF8StringEncoding]; + objCValue = AsString(value); + if (objCValue == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + OnFailureFn(context, err); + return; + } DispatchSuccess(context, objCValue); }; @@ -107,7 +114,12 @@ if (value.IsNull()) { objCValue = nil; } else { - objCValue = [[NSString alloc] initWithBytes:value.Value().data() length:value.Value().size() encoding:NSUTF8StringEncoding]; + objCValue = AsString(value.Value()); + if (objCValue == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + OnFailureFn(context, err); + return; + } } DispatchSuccess(context, objCValue); }; @@ -2478,7 +2490,7 @@ auto & entry_0 = iter_0.GetValue(); MTRAccessControlClusterAccessControlExtensionStruct * newElement_0; newElement_0 = [MTRAccessControlClusterAccessControlExtensionStruct new]; - newElement_0.data = [NSData dataWithBytes:entry_0.data.data() length:entry_0.data.size()]; + newElement_0.data = AsData(entry_0.data); newElement_0.fabricIndex = [NSNumber numberWithUnsignedChar:entry_0.fabricIndex]; [array_0 addObject:newElement_0]; } @@ -2671,9 +2683,12 @@ MTRActionsClusterActionStruct * newElement_0; newElement_0 = [MTRActionsClusterActionStruct new]; newElement_0.actionID = [NSNumber numberWithUnsignedShort:entry_0.actionID]; - newElement_0.name = [[NSString alloc] initWithBytes:entry_0.name.data() - length:entry_0.name.size() - encoding:NSUTF8StringEncoding]; + newElement_0.name = AsString(entry_0.name); + if (newElement_0.name == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + OnFailureFn(context, err); + return; + } newElement_0.type = [NSNumber numberWithUnsignedChar:chip::to_underlying(entry_0.type)]; newElement_0.endpointListID = [NSNumber numberWithUnsignedShort:entry_0.endpointListID]; newElement_0.supportedCommands = [NSNumber numberWithUnsignedShort:entry_0.supportedCommands.Raw()]; @@ -2717,9 +2732,12 @@ MTRActionsClusterEndpointListStruct * newElement_0; newElement_0 = [MTRActionsClusterEndpointListStruct new]; newElement_0.endpointListID = [NSNumber numberWithUnsignedShort:entry_0.endpointListID]; - newElement_0.name = [[NSString alloc] initWithBytes:entry_0.name.data() - length:entry_0.name.size() - encoding:NSUTF8StringEncoding]; + newElement_0.name = AsString(entry_0.name); + if (newElement_0.name == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + OnFailureFn(context, err); + return; + } newElement_0.type = [NSNumber numberWithUnsignedChar:chip::to_underlying(entry_0.type)]; { // Scope for our temporary variables auto * array_2 = [NSMutableArray new]; @@ -3478,7 +3496,12 @@ while (iter_0.Next()) { auto & entry_0 = iter_0.GetValue(); NSString * newElement_0; - newElement_0 = [[NSString alloc] initWithBytes:entry_0.data() length:entry_0.size() encoding:NSUTF8StringEncoding]; + newElement_0 = AsString(entry_0); + if (newElement_0 == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + OnFailureFn(context, err); + return; + } [array_0 addObject:newElement_0]; } CHIP_ERROR err = iter_0.GetStatus(); @@ -4645,7 +4668,7 @@ auto & entry_0 = iter_0.GetValue(); MTRNetworkCommissioningClusterNetworkInfo * newElement_0; newElement_0 = [MTRNetworkCommissioningClusterNetworkInfo new]; - newElement_0.networkID = [NSData dataWithBytes:entry_0.networkID.data() length:entry_0.networkID.size()]; + newElement_0.networkID = AsData(entry_0.networkID); newElement_0.connected = [NSNumber numberWithBool:entry_0.connected]; [array_0 addObject:newElement_0]; } @@ -4990,9 +5013,12 @@ auto & entry_0 = iter_0.GetValue(); MTRGeneralDiagnosticsClusterNetworkInterface * newElement_0; newElement_0 = [MTRGeneralDiagnosticsClusterNetworkInterface new]; - newElement_0.name = [[NSString alloc] initWithBytes:entry_0.name.data() - length:entry_0.name.size() - encoding:NSUTF8StringEncoding]; + newElement_0.name = AsString(entry_0.name); + if (newElement_0.name == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + OnFailureFn(context, err); + return; + } newElement_0.isOperational = [NSNumber numberWithBool:entry_0.isOperational]; if (entry_0.offPremiseServicesReachableIPv4.IsNull()) { newElement_0.offPremiseServicesReachableIPv4 = nil; @@ -5006,15 +5032,14 @@ newElement_0.offPremiseServicesReachableIPv6 = [NSNumber numberWithBool:entry_0.offPremiseServicesReachableIPv6.Value()]; } - newElement_0.hardwareAddress = [NSData dataWithBytes:entry_0.hardwareAddress.data() - length:entry_0.hardwareAddress.size()]; + newElement_0.hardwareAddress = AsData(entry_0.hardwareAddress); { // Scope for our temporary variables auto * array_2 = [NSMutableArray new]; auto iter_2 = entry_0.IPv4Addresses.begin(); while (iter_2.Next()) { auto & entry_2 = iter_2.GetValue(); NSData * newElement_2; - newElement_2 = [NSData dataWithBytes:entry_2.data() length:entry_2.size()]; + newElement_2 = AsData(entry_2); [array_2 addObject:newElement_2]; } CHIP_ERROR err = iter_2.GetStatus(); @@ -5030,7 +5055,7 @@ while (iter_2.Next()) { auto & entry_2 = iter_2.GetValue(); NSData * newElement_2; - newElement_2 = [NSData dataWithBytes:entry_2.data() length:entry_2.size()]; + newElement_2 = AsData(entry_2); [array_2 addObject:newElement_2]; } CHIP_ERROR err = iter_2.GetStatus(); @@ -5348,9 +5373,12 @@ newElement_0 = [MTRSoftwareDiagnosticsClusterThreadMetricsStruct new]; newElement_0.id = [NSNumber numberWithUnsignedLongLong:entry_0.id]; if (entry_0.name.HasValue()) { - newElement_0.name = [[NSString alloc] initWithBytes:entry_0.name.Value().data() - length:entry_0.name.Value().size() - encoding:NSUTF8StringEncoding]; + newElement_0.name = AsString(entry_0.name.Value()); + if (newElement_0.name == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + OnFailureFn(context, err); + return; + } } else { newElement_0.name = nil; } @@ -6757,11 +6785,11 @@ auto & entry_0 = iter_0.GetValue(); MTROperationalCredentialsClusterNOCStruct * newElement_0; newElement_0 = [MTROperationalCredentialsClusterNOCStruct new]; - newElement_0.noc = [NSData dataWithBytes:entry_0.noc.data() length:entry_0.noc.size()]; + newElement_0.noc = AsData(entry_0.noc); if (entry_0.icac.IsNull()) { newElement_0.icac = nil; } else { - newElement_0.icac = [NSData dataWithBytes:entry_0.icac.Value().data() length:entry_0.icac.Value().size()]; + newElement_0.icac = AsData(entry_0.icac.Value()); } newElement_0.fabricIndex = [NSNumber numberWithUnsignedChar:entry_0.fabricIndex]; [array_0 addObject:newElement_0]; @@ -6803,13 +6831,16 @@ auto & entry_0 = iter_0.GetValue(); MTROperationalCredentialsClusterFabricDescriptorStruct * newElement_0; newElement_0 = [MTROperationalCredentialsClusterFabricDescriptorStruct new]; - newElement_0.rootPublicKey = [NSData dataWithBytes:entry_0.rootPublicKey.data() length:entry_0.rootPublicKey.size()]; + newElement_0.rootPublicKey = AsData(entry_0.rootPublicKey); newElement_0.vendorID = [NSNumber numberWithUnsignedShort:chip::to_underlying(entry_0.vendorID)]; newElement_0.fabricID = [NSNumber numberWithUnsignedLongLong:entry_0.fabricID]; newElement_0.nodeID = [NSNumber numberWithUnsignedLongLong:entry_0.nodeID]; - newElement_0.label = [[NSString alloc] initWithBytes:entry_0.label.data() - length:entry_0.label.size() - encoding:NSUTF8StringEncoding]; + newElement_0.label = AsString(entry_0.label); + if (newElement_0.label == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + OnFailureFn(context, err); + return; + } newElement_0.fabricIndex = [NSNumber numberWithUnsignedChar:entry_0.fabricIndex]; [array_0 addObject:newElement_0]; } @@ -6848,7 +6879,7 @@ while (iter_0.Next()) { auto & entry_0 = iter_0.GetValue(); NSData * newElement_0; - newElement_0 = [NSData dataWithBytes:entry_0.data() length:entry_0.size()]; + newElement_0 = AsData(entry_0); [array_0 addObject:newElement_0]; } CHIP_ERROR err = iter_0.GetStatus(); @@ -7100,9 +7131,12 @@ newElement_0.endpoints = array_2; } if (entry_0.groupName.HasValue()) { - newElement_0.groupName = [[NSString alloc] initWithBytes:entry_0.groupName.Value().data() - length:entry_0.groupName.Value().size() - encoding:NSUTF8StringEncoding]; + newElement_0.groupName = AsString(entry_0.groupName.Value()); + if (newElement_0.groupName == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + OnFailureFn(context, err); + return; + } } else { newElement_0.groupName = nil; } @@ -7297,12 +7331,18 @@ auto & entry_0 = iter_0.GetValue(); MTRFixedLabelClusterLabelStruct * newElement_0; newElement_0 = [MTRFixedLabelClusterLabelStruct new]; - newElement_0.label = [[NSString alloc] initWithBytes:entry_0.label.data() - length:entry_0.label.size() - encoding:NSUTF8StringEncoding]; - newElement_0.value = [[NSString alloc] initWithBytes:entry_0.value.data() - length:entry_0.value.size() - encoding:NSUTF8StringEncoding]; + newElement_0.label = AsString(entry_0.label); + if (newElement_0.label == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + OnFailureFn(context, err); + return; + } + newElement_0.value = AsString(entry_0.value); + if (newElement_0.value == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + OnFailureFn(context, err); + return; + } [array_0 addObject:newElement_0]; } CHIP_ERROR err = iter_0.GetStatus(); @@ -7493,12 +7533,18 @@ auto & entry_0 = iter_0.GetValue(); MTRUserLabelClusterLabelStruct * newElement_0; newElement_0 = [MTRUserLabelClusterLabelStruct new]; - newElement_0.label = [[NSString alloc] initWithBytes:entry_0.label.data() - length:entry_0.label.size() - encoding:NSUTF8StringEncoding]; - newElement_0.value = [[NSString alloc] initWithBytes:entry_0.value.data() - length:entry_0.value.size() - encoding:NSUTF8StringEncoding]; + newElement_0.label = AsString(entry_0.label); + if (newElement_0.label == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + OnFailureFn(context, err); + return; + } + newElement_0.value = AsString(entry_0.value); + if (newElement_0.value == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + OnFailureFn(context, err); + return; + } [array_0 addObject:newElement_0]; } CHIP_ERROR err = iter_0.GetStatus(); @@ -7955,9 +8001,12 @@ auto & entry_0 = iter_0.GetValue(); MTRModeSelectClusterModeOptionStruct * newElement_0; newElement_0 = [MTRModeSelectClusterModeOptionStruct new]; - newElement_0.label = [[NSString alloc] initWithBytes:entry_0.label.data() - length:entry_0.label.size() - encoding:NSUTF8StringEncoding]; + newElement_0.label = AsString(entry_0.label); + if (newElement_0.label == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + OnFailureFn(context, err); + return; + } newElement_0.mode = [NSNumber numberWithUnsignedChar:entry_0.mode]; { // Scope for our temporary variables auto * array_2 = [NSMutableArray new]; @@ -8168,9 +8217,12 @@ auto & entry_0 = iter_0.GetValue(); MTRTemperatureControlClusterTemperatureLevelStruct * newElement_0; newElement_0 = [MTRTemperatureControlClusterTemperatureLevelStruct new]; - newElement_0.label = [[NSString alloc] initWithBytes:entry_0.label.data() - length:entry_0.label.size() - encoding:NSUTF8StringEncoding]; + newElement_0.label = AsString(entry_0.label); + if (newElement_0.label == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + OnFailureFn(context, err); + return; + } newElement_0.temperatureLevel = [NSNumber numberWithUnsignedChar:entry_0.temperatureLevel]; [array_0 addObject:newElement_0]; } @@ -18902,23 +18954,32 @@ newElement_0.majorNumber = [NSNumber numberWithUnsignedShort:entry_0.majorNumber]; newElement_0.minorNumber = [NSNumber numberWithUnsignedShort:entry_0.minorNumber]; if (entry_0.name.HasValue()) { - newElement_0.name = [[NSString alloc] initWithBytes:entry_0.name.Value().data() - length:entry_0.name.Value().size() - encoding:NSUTF8StringEncoding]; + newElement_0.name = AsString(entry_0.name.Value()); + if (newElement_0.name == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + OnFailureFn(context, err); + return; + } } else { newElement_0.name = nil; } if (entry_0.callSign.HasValue()) { - newElement_0.callSign = [[NSString alloc] initWithBytes:entry_0.callSign.Value().data() - length:entry_0.callSign.Value().size() - encoding:NSUTF8StringEncoding]; + newElement_0.callSign = AsString(entry_0.callSign.Value()); + if (newElement_0.callSign == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + OnFailureFn(context, err); + return; + } } else { newElement_0.callSign = nil; } if (entry_0.affiliateCallSign.HasValue()) { - newElement_0.affiliateCallSign = [[NSString alloc] initWithBytes:entry_0.affiliateCallSign.Value().data() - length:entry_0.affiliateCallSign.Value().size() - encoding:NSUTF8StringEncoding]; + newElement_0.affiliateCallSign = AsString(entry_0.affiliateCallSign.Value()); + if (newElement_0.affiliateCallSign == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + OnFailureFn(context, err); + return; + } } else { newElement_0.affiliateCallSign = nil; } @@ -18957,20 +19018,29 @@ objCValue = nil; } else { objCValue = [MTRChannelClusterLineupInfoStruct new]; - objCValue.operatorName = [[NSString alloc] initWithBytes:value.Value().operatorName.data() - length:value.Value().operatorName.size() - encoding:NSUTF8StringEncoding]; + objCValue.operatorName = AsString(value.Value().operatorName); + if (objCValue.operatorName == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + OnFailureFn(context, err); + return; + } if (value.Value().lineupName.HasValue()) { - objCValue.lineupName = [[NSString alloc] initWithBytes:value.Value().lineupName.Value().data() - length:value.Value().lineupName.Value().size() - encoding:NSUTF8StringEncoding]; + objCValue.lineupName = AsString(value.Value().lineupName.Value()); + if (objCValue.lineupName == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + OnFailureFn(context, err); + return; + } } else { objCValue.lineupName = nil; } if (value.Value().postalCode.HasValue()) { - objCValue.postalCode = [[NSString alloc] initWithBytes:value.Value().postalCode.Value().data() - length:value.Value().postalCode.Value().size() - encoding:NSUTF8StringEncoding]; + objCValue.postalCode = AsString(value.Value().postalCode.Value()); + if (objCValue.postalCode == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + OnFailureFn(context, err); + return; + } } else { objCValue.postalCode = nil; } @@ -19005,23 +19075,32 @@ objCValue.majorNumber = [NSNumber numberWithUnsignedShort:value.Value().majorNumber]; objCValue.minorNumber = [NSNumber numberWithUnsignedShort:value.Value().minorNumber]; if (value.Value().name.HasValue()) { - objCValue.name = [[NSString alloc] initWithBytes:value.Value().name.Value().data() - length:value.Value().name.Value().size() - encoding:NSUTF8StringEncoding]; + objCValue.name = AsString(value.Value().name.Value()); + if (objCValue.name == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + OnFailureFn(context, err); + return; + } } else { objCValue.name = nil; } if (value.Value().callSign.HasValue()) { - objCValue.callSign = [[NSString alloc] initWithBytes:value.Value().callSign.Value().data() - length:value.Value().callSign.Value().size() - encoding:NSUTF8StringEncoding]; + objCValue.callSign = AsString(value.Value().callSign.Value()); + if (objCValue.callSign == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + OnFailureFn(context, err); + return; + } } else { objCValue.callSign = nil; } if (value.Value().affiliateCallSign.HasValue()) { - objCValue.affiliateCallSign = [[NSString alloc] initWithBytes:value.Value().affiliateCallSign.Value().data() - length:value.Value().affiliateCallSign.Value().size() - encoding:NSUTF8StringEncoding]; + objCValue.affiliateCallSign = AsString(value.Value().affiliateCallSign.Value()); + if (objCValue.affiliateCallSign == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + OnFailureFn(context, err); + return; + } } else { objCValue.affiliateCallSign = nil; } @@ -19209,9 +19288,12 @@ MTRTargetNavigatorClusterTargetInfoStruct * newElement_0; newElement_0 = [MTRTargetNavigatorClusterTargetInfoStruct new]; newElement_0.identifier = [NSNumber numberWithUnsignedChar:entry_0.identifier]; - newElement_0.name = [[NSString alloc] initWithBytes:entry_0.name.data() - length:entry_0.name.size() - encoding:NSUTF8StringEncoding]; + newElement_0.name = AsString(entry_0.name); + if (newElement_0.name == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + OnFailureFn(context, err); + return; + } [array_0 addObject:newElement_0]; } CHIP_ERROR err = iter_0.GetStatus(); @@ -19590,12 +19672,18 @@ newElement_0 = [MTRMediaInputClusterInputInfoStruct new]; newElement_0.index = [NSNumber numberWithUnsignedChar:entry_0.index]; newElement_0.inputType = [NSNumber numberWithUnsignedChar:chip::to_underlying(entry_0.inputType)]; - newElement_0.name = [[NSString alloc] initWithBytes:entry_0.name.data() - length:entry_0.name.size() - encoding:NSUTF8StringEncoding]; - newElement_0.descriptionString = [[NSString alloc] initWithBytes:entry_0.description.data() - length:entry_0.description.size() - encoding:NSUTF8StringEncoding]; + newElement_0.name = AsString(entry_0.name); + if (newElement_0.name == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + OnFailureFn(context, err); + return; + } + newElement_0.descriptionString = AsString(entry_0.description); + if (newElement_0.descriptionString == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + OnFailureFn(context, err); + return; + } [array_0 addObject:newElement_0]; } CHIP_ERROR err = iter_0.GetStatus(); @@ -20089,7 +20177,12 @@ while (iter_0.Next()) { auto & entry_0 = iter_0.GetValue(); NSString * newElement_0; - newElement_0 = [[NSString alloc] initWithBytes:entry_0.data() length:entry_0.size() encoding:NSUTF8StringEncoding]; + newElement_0 = AsString(entry_0); + if (newElement_0 == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + OnFailureFn(context, err); + return; + } [array_0 addObject:newElement_0]; } CHIP_ERROR err = iter_0.GetStatus(); @@ -20282,9 +20375,12 @@ newElement_0 = [MTRAudioOutputClusterOutputInfoStruct new]; newElement_0.index = [NSNumber numberWithUnsignedChar:entry_0.index]; newElement_0.outputType = [NSNumber numberWithUnsignedChar:chip::to_underlying(entry_0.outputType)]; - newElement_0.name = [[NSString alloc] initWithBytes:entry_0.name.data() - length:entry_0.name.size() - encoding:NSUTF8StringEncoding]; + newElement_0.name = AsString(entry_0.name); + if (newElement_0.name == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + OnFailureFn(context, err); + return; + } [array_0 addObject:newElement_0]; } CHIP_ERROR err = iter_0.GetStatus(); @@ -20513,9 +20609,12 @@ objCValue = [MTRApplicationLauncherClusterApplicationEPStruct new]; objCValue.application = [MTRApplicationLauncherClusterApplicationStruct new]; objCValue.application.catalogVendorID = [NSNumber numberWithUnsignedShort:value.Value().application.catalogVendorID]; - objCValue.application.applicationID = [[NSString alloc] initWithBytes:value.Value().application.applicationID.data() - length:value.Value().application.applicationID.size() - encoding:NSUTF8StringEncoding]; + objCValue.application.applicationID = AsString(value.Value().application.applicationID); + if (objCValue.application.applicationID == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + OnFailureFn(context, err); + return; + } if (value.Value().endpoint.HasValue()) { objCValue.endpoint = [NSNumber numberWithUnsignedShort:value.Value().endpoint.Value()]; } else { @@ -20698,9 +20797,12 @@ MTRApplicationBasicClusterApplicationStruct * _Nonnull objCValue; objCValue = [MTRApplicationBasicClusterApplicationStruct new]; objCValue.catalogVendorID = [NSNumber numberWithUnsignedShort:value.catalogVendorID]; - objCValue.applicationID = [[NSString alloc] initWithBytes:value.applicationID.data() - length:value.applicationID.size() - encoding:NSUTF8StringEncoding]; + objCValue.applicationID = AsString(value.applicationID); + if (objCValue.applicationID == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + OnFailureFn(context, err); + return; + } DispatchSuccess(context, objCValue); }; @@ -21353,7 +21455,7 @@ while (iter_0.Next()) { auto & entry_0 = iter_0.GetValue(); NSData * newElement_0; - newElement_0 = [NSData dataWithBytes:entry_0.data() length:entry_0.size()]; + newElement_0 = AsData(entry_0); [array_0 addObject:newElement_0]; } CHIP_ERROR err = iter_0.GetStatus(); @@ -21394,7 +21496,7 @@ MTRUnitTestingClusterTestListStructOctet * newElement_0; newElement_0 = [MTRUnitTestingClusterTestListStructOctet new]; newElement_0.member1 = [NSNumber numberWithUnsignedLongLong:entry_0.member1]; - newElement_0.member2 = [NSData dataWithBytes:entry_0.member2.data() length:entry_0.member2.size()]; + newElement_0.member2 = AsData(entry_0.member2); [array_0 addObject:newElement_0]; } CHIP_ERROR err = iter_0.GetStatus(); @@ -21457,14 +21559,20 @@ if (entry_0.nullableString.IsNull()) { newElement_0.nullableString = nil; } else { - newElement_0.nullableString = [[NSString alloc] initWithBytes:entry_0.nullableString.Value().data() - length:entry_0.nullableString.Value().size() - encoding:NSUTF8StringEncoding]; + newElement_0.nullableString = AsString(entry_0.nullableString.Value()); + if (newElement_0.nullableString == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + OnFailureFn(context, err); + return; + } } if (entry_0.optionalString.HasValue()) { - newElement_0.optionalString = [[NSString alloc] initWithBytes:entry_0.optionalString.Value().data() - length:entry_0.optionalString.Value().size() - encoding:NSUTF8StringEncoding]; + newElement_0.optionalString = AsString(entry_0.optionalString.Value()); + if (newElement_0.optionalString == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + OnFailureFn(context, err); + return; + } } else { newElement_0.optionalString = nil; } @@ -21472,10 +21580,12 @@ if (entry_0.nullableOptionalString.Value().IsNull()) { newElement_0.nullableOptionalString = nil; } else { - newElement_0.nullableOptionalString = - [[NSString alloc] initWithBytes:entry_0.nullableOptionalString.Value().Value().data() - length:entry_0.nullableOptionalString.Value().Value().size() - encoding:NSUTF8StringEncoding]; + newElement_0.nullableOptionalString = AsString(entry_0.nullableOptionalString.Value().Value()); + if (newElement_0.nullableOptionalString == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + OnFailureFn(context, err); + return; + } } } else { newElement_0.nullableOptionalString = nil; @@ -21488,11 +21598,13 @@ newElement_0.nullableStruct.b = [NSNumber numberWithBool:entry_0.nullableStruct.Value().b]; newElement_0.nullableStruct.c = [NSNumber numberWithUnsignedChar:chip::to_underlying(entry_0.nullableStruct.Value().c)]; - newElement_0.nullableStruct.d = [NSData dataWithBytes:entry_0.nullableStruct.Value().d.data() - length:entry_0.nullableStruct.Value().d.size()]; - newElement_0.nullableStruct.e = [[NSString alloc] initWithBytes:entry_0.nullableStruct.Value().e.data() - length:entry_0.nullableStruct.Value().e.size() - encoding:NSUTF8StringEncoding]; + newElement_0.nullableStruct.d = AsData(entry_0.nullableStruct.Value().d); + newElement_0.nullableStruct.e = AsString(entry_0.nullableStruct.Value().e); + if (newElement_0.nullableStruct.e == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + OnFailureFn(context, err); + return; + } newElement_0.nullableStruct.f = [NSNumber numberWithUnsignedChar:entry_0.nullableStruct.Value().f.Raw()]; newElement_0.nullableStruct.g = [NSNumber numberWithFloat:entry_0.nullableStruct.Value().g]; newElement_0.nullableStruct.h = [NSNumber numberWithDouble:entry_0.nullableStruct.Value().h]; @@ -21503,11 +21615,13 @@ newElement_0.optionalStruct.b = [NSNumber numberWithBool:entry_0.optionalStruct.Value().b]; newElement_0.optionalStruct.c = [NSNumber numberWithUnsignedChar:chip::to_underlying(entry_0.optionalStruct.Value().c)]; - newElement_0.optionalStruct.d = [NSData dataWithBytes:entry_0.optionalStruct.Value().d.data() - length:entry_0.optionalStruct.Value().d.size()]; - newElement_0.optionalStruct.e = [[NSString alloc] initWithBytes:entry_0.optionalStruct.Value().e.data() - length:entry_0.optionalStruct.Value().e.size() - encoding:NSUTF8StringEncoding]; + newElement_0.optionalStruct.d = AsData(entry_0.optionalStruct.Value().d); + newElement_0.optionalStruct.e = AsString(entry_0.optionalStruct.Value().e); + if (newElement_0.optionalStruct.e == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + OnFailureFn(context, err); + return; + } newElement_0.optionalStruct.f = [NSNumber numberWithUnsignedChar:entry_0.optionalStruct.Value().f.Raw()]; newElement_0.optionalStruct.g = [NSNumber numberWithFloat:entry_0.optionalStruct.Value().g]; newElement_0.optionalStruct.h = [NSNumber numberWithDouble:entry_0.optionalStruct.Value().h]; @@ -21525,13 +21639,13 @@ [NSNumber numberWithBool:entry_0.nullableOptionalStruct.Value().Value().b]; newElement_0.nullableOptionalStruct.c = [NSNumber numberWithUnsignedChar:chip::to_underlying(entry_0.nullableOptionalStruct.Value().Value().c)]; - newElement_0.nullableOptionalStruct.d = - [NSData dataWithBytes:entry_0.nullableOptionalStruct.Value().Value().d.data() - length:entry_0.nullableOptionalStruct.Value().Value().d.size()]; - newElement_0.nullableOptionalStruct.e = - [[NSString alloc] initWithBytes:entry_0.nullableOptionalStruct.Value().Value().e.data() - length:entry_0.nullableOptionalStruct.Value().Value().e.size() - encoding:NSUTF8StringEncoding]; + newElement_0.nullableOptionalStruct.d = AsData(entry_0.nullableOptionalStruct.Value().Value().d); + newElement_0.nullableOptionalStruct.e = AsString(entry_0.nullableOptionalStruct.Value().Value().e); + if (newElement_0.nullableOptionalStruct.e == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + OnFailureFn(context, err); + return; + } newElement_0.nullableOptionalStruct.f = [NSNumber numberWithUnsignedChar:entry_0.nullableOptionalStruct.Value().Value().f.Raw()]; newElement_0.nullableOptionalStruct.g = @@ -21641,8 +21755,13 @@ objCValue.a = [NSNumber numberWithUnsignedChar:value.a]; objCValue.b = [NSNumber numberWithBool:value.b]; objCValue.c = [NSNumber numberWithUnsignedChar:chip::to_underlying(value.c)]; - objCValue.d = [NSData dataWithBytes:value.d.data() length:value.d.size()]; - objCValue.e = [[NSString alloc] initWithBytes:value.e.data() length:value.e.size() encoding:NSUTF8StringEncoding]; + objCValue.d = AsData(value.d); + objCValue.e = AsString(value.e); + if (objCValue.e == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + OnFailureFn(context, err); + return; + } objCValue.f = [NSNumber numberWithUnsignedChar:value.f.Raw()]; objCValue.g = [NSNumber numberWithFloat:value.g]; objCValue.h = [NSNumber numberWithDouble:value.h]; @@ -21674,7 +21793,7 @@ while (iter_0.Next()) { auto & entry_0 = iter_0.GetValue(); NSData * newElement_0; - newElement_0 = [NSData dataWithBytes:entry_0.data() length:entry_0.size()]; + newElement_0 = AsData(entry_0); [array_0 addObject:newElement_0]; } CHIP_ERROR err = iter_0.GetStatus(); @@ -21736,19 +21855,24 @@ } else { newElement_0.nullableOptionalFabricSensitiveInt8u = nil; } - newElement_0.fabricSensitiveCharString = [[NSString alloc] initWithBytes:entry_0.fabricSensitiveCharString.data() - length:entry_0.fabricSensitiveCharString.size() - encoding:NSUTF8StringEncoding]; + newElement_0.fabricSensitiveCharString = AsString(entry_0.fabricSensitiveCharString); + if (newElement_0.fabricSensitiveCharString == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + OnFailureFn(context, err); + return; + } newElement_0.fabricSensitiveStruct = [MTRUnitTestingClusterSimpleStruct new]; newElement_0.fabricSensitiveStruct.a = [NSNumber numberWithUnsignedChar:entry_0.fabricSensitiveStruct.a]; newElement_0.fabricSensitiveStruct.b = [NSNumber numberWithBool:entry_0.fabricSensitiveStruct.b]; newElement_0.fabricSensitiveStruct.c = [NSNumber numberWithUnsignedChar:chip::to_underlying(entry_0.fabricSensitiveStruct.c)]; - newElement_0.fabricSensitiveStruct.d = [NSData dataWithBytes:entry_0.fabricSensitiveStruct.d.data() - length:entry_0.fabricSensitiveStruct.d.size()]; - newElement_0.fabricSensitiveStruct.e = [[NSString alloc] initWithBytes:entry_0.fabricSensitiveStruct.e.data() - length:entry_0.fabricSensitiveStruct.e.size() - encoding:NSUTF8StringEncoding]; + newElement_0.fabricSensitiveStruct.d = AsData(entry_0.fabricSensitiveStruct.d); + newElement_0.fabricSensitiveStruct.e = AsString(entry_0.fabricSensitiveStruct.e); + if (newElement_0.fabricSensitiveStruct.e == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + OnFailureFn(context, err); + return; + } newElement_0.fabricSensitiveStruct.f = [NSNumber numberWithUnsignedChar:entry_0.fabricSensitiveStruct.f.Raw()]; newElement_0.fabricSensitiveStruct.g = [NSNumber numberWithFloat:entry_0.fabricSensitiveStruct.g]; newElement_0.fabricSensitiveStruct.h = [NSNumber numberWithDouble:entry_0.fabricSensitiveStruct.h]; @@ -21915,10 +22039,13 @@ objCValue.a = [NSNumber numberWithUnsignedChar:value.Value().a]; objCValue.b = [NSNumber numberWithBool:value.Value().b]; objCValue.c = [NSNumber numberWithUnsignedChar:chip::to_underlying(value.Value().c)]; - objCValue.d = [NSData dataWithBytes:value.Value().d.data() length:value.Value().d.size()]; - objCValue.e = [[NSString alloc] initWithBytes:value.Value().e.data() - length:value.Value().e.size() - encoding:NSUTF8StringEncoding]; + objCValue.d = AsData(value.Value().d); + objCValue.e = AsString(value.Value().e); + if (objCValue.e == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + OnFailureFn(context, err); + return; + } objCValue.f = [NSNumber numberWithUnsignedChar:value.Value().f.Raw()]; objCValue.g = [NSNumber numberWithFloat:value.Value().g]; objCValue.h = [NSNumber numberWithDouble:value.Value().h]; diff --git a/src/darwin/Framework/CHIP/zap-generated/MTRCommandPayloadsObjc.mm b/src/darwin/Framework/CHIP/zap-generated/MTRCommandPayloadsObjc.mm index 71ab972068f489..67732009ad5c4c 100644 --- a/src/darwin/Framework/CHIP/zap-generated/MTRCommandPayloadsObjc.mm +++ b/src/darwin/Framework/CHIP/zap-generated/MTRCommandPayloadsObjc.mm @@ -20,6 +20,8 @@ #import "MTRCommandPayloads_Internal.h" #import "MTRError_Internal.h" #import "MTRLogging_Internal.h" +#import "NSDataSpanConversion.h" +#import "NSStringSpanConversion.h" #include #include @@ -369,9 +371,11 @@ - (CHIP_ERROR)_setFieldsFromDecodableStruct: self.groupID = [NSNumber numberWithUnsignedShort:decodableStruct.groupID]; } { - self.groupName = [[NSString alloc] initWithBytes:decodableStruct.groupName.data() - length:decodableStruct.groupName.size() - encoding:NSUTF8StringEncoding]; + self.groupName = AsString(decodableStruct.groupName); + if (self.groupName == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + return err; + } } return CHIP_NO_ERROR; } @@ -1090,9 +1094,11 @@ - (CHIP_ERROR)_setFieldsFromDecodableStruct: } { if (decodableStruct.sceneName.HasValue()) { - self.sceneName = [[NSString alloc] initWithBytes:decodableStruct.sceneName.Value().data() - length:decodableStruct.sceneName.Value().size() - encoding:NSUTF8StringEncoding]; + self.sceneName = AsString(decodableStruct.sceneName.Value()); + if (self.sceneName == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + return err; + } } else { self.sceneName = nil; } @@ -2241,9 +2247,11 @@ - (CHIP_ERROR)_setFieldsFromDecodableStruct: } { if (decodableStruct.sceneName.HasValue()) { - self.sceneName = [[NSString alloc] initWithBytes:decodableStruct.sceneName.Value().data() - length:decodableStruct.sceneName.Value().size() - encoding:NSUTF8StringEncoding]; + self.sceneName = AsString(decodableStruct.sceneName.Value()); + if (self.sceneName == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + return err; + } } else { self.sceneName = nil; } @@ -3704,9 +3712,11 @@ - (CHIP_ERROR)_setFieldsFromDecodableStruct: } { if (decodableStruct.imageURI.HasValue()) { - self.imageURI = [[NSString alloc] initWithBytes:decodableStruct.imageURI.Value().data() - length:decodableStruct.imageURI.Value().size() - encoding:NSUTF8StringEncoding]; + self.imageURI = AsString(decodableStruct.imageURI.Value()); + if (self.imageURI == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + return err; + } } else { self.imageURI = nil; } @@ -3720,17 +3730,18 @@ - (CHIP_ERROR)_setFieldsFromDecodableStruct: } { if (decodableStruct.softwareVersionString.HasValue()) { - self.softwareVersionString = [[NSString alloc] initWithBytes:decodableStruct.softwareVersionString.Value().data() - length:decodableStruct.softwareVersionString.Value().size() - encoding:NSUTF8StringEncoding]; + self.softwareVersionString = AsString(decodableStruct.softwareVersionString.Value()); + if (self.softwareVersionString == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + return err; + } } else { self.softwareVersionString = nil; } } { if (decodableStruct.updateToken.HasValue()) { - self.updateToken = [NSData dataWithBytes:decodableStruct.updateToken.Value().data() - length:decodableStruct.updateToken.Value().size()]; + self.updateToken = AsData(decodableStruct.updateToken.Value()); } else { self.updateToken = nil; } @@ -3744,8 +3755,7 @@ - (CHIP_ERROR)_setFieldsFromDecodableStruct: } { if (decodableStruct.metadataForRequestor.HasValue()) { - self.metadataForRequestor = [NSData dataWithBytes:decodableStruct.metadataForRequestor.Value().data() - length:decodableStruct.metadataForRequestor.Value().size()]; + self.metadataForRequestor = AsData(decodableStruct.metadataForRequestor.Value()); } else { self.metadataForRequestor = nil; } @@ -4109,9 +4119,11 @@ - (CHIP_ERROR)_setFieldsFromDecodableStruct: self.errorCode = [NSNumber numberWithUnsignedChar:chip::to_underlying(decodableStruct.errorCode)]; } { - self.debugText = [[NSString alloc] initWithBytes:decodableStruct.debugText.data() - length:decodableStruct.debugText.size() - encoding:NSUTF8StringEncoding]; + self.debugText = AsString(decodableStruct.debugText); + if (self.debugText == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + return err; + } } return CHIP_NO_ERROR; } @@ -4235,9 +4247,11 @@ - (CHIP_ERROR)_setFieldsFromDecodableStruct: self.errorCode = [NSNumber numberWithUnsignedChar:chip::to_underlying(decodableStruct.errorCode)]; } { - self.debugText = [[NSString alloc] initWithBytes:decodableStruct.debugText.data() - length:decodableStruct.debugText.size() - encoding:NSUTF8StringEncoding]; + self.debugText = AsString(decodableStruct.debugText); + if (self.debugText == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + return err; + } } return CHIP_NO_ERROR; } @@ -4351,9 +4365,11 @@ - (CHIP_ERROR)_setFieldsFromDecodableStruct: self.errorCode = [NSNumber numberWithUnsignedChar:chip::to_underlying(decodableStruct.errorCode)]; } { - self.debugText = [[NSString alloc] initWithBytes:decodableStruct.debugText.data() - length:decodableStruct.debugText.size() - encoding:NSUTF8StringEncoding]; + self.debugText = AsString(decodableStruct.debugText); + if (self.debugText == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + return err; + } } return CHIP_NO_ERROR; } @@ -4482,9 +4498,11 @@ - (CHIP_ERROR)_setFieldsFromDecodableStruct: } { if (decodableStruct.debugText.HasValue()) { - self.debugText = [[NSString alloc] initWithBytes:decodableStruct.debugText.Value().data() - length:decodableStruct.debugText.Value().size() - encoding:NSUTF8StringEncoding]; + self.debugText = AsString(decodableStruct.debugText.Value()); + if (self.debugText == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + return err; + } } else { self.debugText = nil; } @@ -4499,8 +4517,8 @@ - (CHIP_ERROR)_setFieldsFromDecodableStruct: MTRNetworkCommissioningClusterWiFiInterfaceScanResult * newElement_1; newElement_1 = [MTRNetworkCommissioningClusterWiFiInterfaceScanResult new]; newElement_1.security = [NSNumber numberWithUnsignedChar:entry_1.security.Raw()]; - newElement_1.ssid = [NSData dataWithBytes:entry_1.ssid.data() length:entry_1.ssid.size()]; - newElement_1.bssid = [NSData dataWithBytes:entry_1.bssid.data() length:entry_1.bssid.size()]; + newElement_1.ssid = AsData(entry_1.ssid); + newElement_1.bssid = AsData(entry_1.bssid); newElement_1.channel = [NSNumber numberWithUnsignedShort:entry_1.channel]; newElement_1.wiFiBand = [NSNumber numberWithUnsignedChar:chip::to_underlying(entry_1.wiFiBand)]; newElement_1.rssi = [NSNumber numberWithChar:entry_1.rssi]; @@ -4527,13 +4545,14 @@ - (CHIP_ERROR)_setFieldsFromDecodableStruct: newElement_1 = [MTRNetworkCommissioningClusterThreadInterfaceScanResult new]; newElement_1.panId = [NSNumber numberWithUnsignedShort:entry_1.panId]; newElement_1.extendedPanId = [NSNumber numberWithUnsignedLongLong:entry_1.extendedPanId]; - newElement_1.networkName = [[NSString alloc] initWithBytes:entry_1.networkName.data() - length:entry_1.networkName.size() - encoding:NSUTF8StringEncoding]; + newElement_1.networkName = AsString(entry_1.networkName); + if (newElement_1.networkName == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + return err; + } newElement_1.channel = [NSNumber numberWithUnsignedShort:entry_1.channel]; newElement_1.version = [NSNumber numberWithUnsignedChar:entry_1.version]; - newElement_1.extendedAddress = [NSData dataWithBytes:entry_1.extendedAddress.data() - length:entry_1.extendedAddress.size()]; + newElement_1.extendedAddress = AsData(entry_1.extendedAddress); newElement_1.rssi = [NSNumber numberWithChar:entry_1.rssi]; newElement_1.lqi = [NSNumber numberWithUnsignedChar:entry_1.lqi]; [array_1 addObject:newElement_1]; @@ -4745,9 +4764,11 @@ - (CHIP_ERROR)_setFieldsFromDecodableStruct: } { if (decodableStruct.debugText.HasValue()) { - self.debugText = [[NSString alloc] initWithBytes:decodableStruct.debugText.Value().data() - length:decodableStruct.debugText.Value().size() - encoding:NSUTF8StringEncoding]; + self.debugText = AsString(decodableStruct.debugText.Value()); + if (self.debugText == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + return err; + } } else { self.debugText = nil; } @@ -4883,9 +4904,11 @@ - (CHIP_ERROR)_setFieldsFromDecodableStruct: } { if (decodableStruct.debugText.HasValue()) { - self.debugText = [[NSString alloc] initWithBytes:decodableStruct.debugText.Value().data() - length:decodableStruct.debugText.Value().size() - encoding:NSUTF8StringEncoding]; + self.debugText = AsString(decodableStruct.debugText.Value()); + if (self.debugText == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + return err; + } } else { self.debugText = nil; } @@ -5064,7 +5087,7 @@ - (CHIP_ERROR)_setFieldsFromDecodableStruct: self.status = [NSNumber numberWithUnsignedChar:chip::to_underlying(decodableStruct.status)]; } { - self.logContent = [NSData dataWithBytes:decodableStruct.logContent.data() length:decodableStruct.logContent.size()]; + self.logContent = AsData(decodableStruct.logContent); } { if (decodableStruct.UTCTimeStamp.HasValue()) { @@ -5513,12 +5536,10 @@ - (CHIP_ERROR)_setFieldsFromDecodableStruct: (const chip::app::Clusters::OperationalCredentials::Commands::AttestationResponse::DecodableType &)decodableStruct { { - self.attestationElements = [NSData dataWithBytes:decodableStruct.attestationElements.data() - length:decodableStruct.attestationElements.size()]; + self.attestationElements = AsData(decodableStruct.attestationElements); } { - self.attestationSignature = [NSData dataWithBytes:decodableStruct.attestationSignature.data() - length:decodableStruct.attestationSignature.size()]; + self.attestationSignature = AsData(decodableStruct.attestationSignature); } return CHIP_NO_ERROR; } @@ -5643,7 +5664,7 @@ - (CHIP_ERROR)_setFieldsFromDecodableStruct: (const chip::app::Clusters::OperationalCredentials::Commands::CertificateChainResponse::DecodableType &)decodableStruct { { - self.certificate = [NSData dataWithBytes:decodableStruct.certificate.data() length:decodableStruct.certificate.size()]; + self.certificate = AsData(decodableStruct.certificate); } return CHIP_NO_ERROR; } @@ -5763,12 +5784,10 @@ - (CHIP_ERROR)_setFieldsFromDecodableStruct: (const chip::app::Clusters::OperationalCredentials::Commands::CSRResponse::DecodableType &)decodableStruct { { - self.nocsrElements = [NSData dataWithBytes:decodableStruct.NOCSRElements.data() - length:decodableStruct.NOCSRElements.size()]; + self.nocsrElements = AsData(decodableStruct.NOCSRElements); } { - self.attestationSignature = [NSData dataWithBytes:decodableStruct.attestationSignature.data() - length:decodableStruct.attestationSignature.size()]; + self.attestationSignature = AsData(decodableStruct.attestationSignature); } return CHIP_NO_ERROR; } @@ -5947,9 +5966,11 @@ - (CHIP_ERROR)_setFieldsFromDecodableStruct: } { if (decodableStruct.debugText.HasValue()) { - self.debugText = [[NSString alloc] initWithBytes:decodableStruct.debugText.Value().data() - length:decodableStruct.debugText.Value().size() - encoding:NSUTF8StringEncoding]; + self.debugText = AsString(decodableStruct.debugText.Value()); + if (self.debugText == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + return err; + } } else { self.debugText = nil; } @@ -6207,8 +6228,7 @@ - (CHIP_ERROR)_setFieldsFromDecodableStruct: if (decodableStruct.groupKeySet.epochKey0.IsNull()) { self.groupKeySet.epochKey0 = nil; } else { - self.groupKeySet.epochKey0 = [NSData dataWithBytes:decodableStruct.groupKeySet.epochKey0.Value().data() - length:decodableStruct.groupKeySet.epochKey0.Value().size()]; + self.groupKeySet.epochKey0 = AsData(decodableStruct.groupKeySet.epochKey0.Value()); } if (decodableStruct.groupKeySet.epochStartTime0.IsNull()) { self.groupKeySet.epochStartTime0 = nil; @@ -6219,8 +6239,7 @@ - (CHIP_ERROR)_setFieldsFromDecodableStruct: if (decodableStruct.groupKeySet.epochKey1.IsNull()) { self.groupKeySet.epochKey1 = nil; } else { - self.groupKeySet.epochKey1 = [NSData dataWithBytes:decodableStruct.groupKeySet.epochKey1.Value().data() - length:decodableStruct.groupKeySet.epochKey1.Value().size()]; + self.groupKeySet.epochKey1 = AsData(decodableStruct.groupKeySet.epochKey1.Value()); } if (decodableStruct.groupKeySet.epochStartTime1.IsNull()) { self.groupKeySet.epochStartTime1 = nil; @@ -6231,8 +6250,7 @@ - (CHIP_ERROR)_setFieldsFromDecodableStruct: if (decodableStruct.groupKeySet.epochKey2.IsNull()) { self.groupKeySet.epochKey2 = nil; } else { - self.groupKeySet.epochKey2 = [NSData dataWithBytes:decodableStruct.groupKeySet.epochKey2.Value().data() - length:decodableStruct.groupKeySet.epochKey2.Value().size()]; + self.groupKeySet.epochKey2 = AsData(decodableStruct.groupKeySet.epochKey2.Value()); } if (decodableStruct.groupKeySet.epochStartTime2.IsNull()) { self.groupKeySet.epochStartTime2 = nil; @@ -7861,9 +7879,11 @@ - (CHIP_ERROR)_setFieldsFromDecodableStruct: if (decodableStruct.userName.IsNull()) { self.userName = nil; } else { - self.userName = [[NSString alloc] initWithBytes:decodableStruct.userName.Value().data() - length:decodableStruct.userName.Value().size() - encoding:NSUTF8StringEncoding]; + self.userName = AsString(decodableStruct.userName.Value()); + if (self.userName == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + return err; + } } } { @@ -9822,9 +9842,11 @@ - (CHIP_ERROR)_setFieldsFromDecodableStruct: } { if (decodableStruct.data.HasValue()) { - self.data = [[NSString alloc] initWithBytes:decodableStruct.data.Value().data() - length:decodableStruct.data.Value().size() - encoding:NSUTF8StringEncoding]; + self.data = AsString(decodableStruct.data.Value()); + if (self.data == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + return err; + } } else { self.data = nil; } @@ -10013,9 +10035,11 @@ - (CHIP_ERROR)_setFieldsFromDecodableStruct: } { if (decodableStruct.data.HasValue()) { - self.data = [[NSString alloc] initWithBytes:decodableStruct.data.Value().data() - length:decodableStruct.data.Value().size() - encoding:NSUTF8StringEncoding]; + self.data = AsString(decodableStruct.data.Value()); + if (self.data == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + return err; + } } else { self.data = nil; } @@ -10387,9 +10411,11 @@ - (CHIP_ERROR)_setFieldsFromDecodableStruct: } { if (decodableStruct.data.HasValue()) { - self.data = [[NSString alloc] initWithBytes:decodableStruct.data.Value().data() - length:decodableStruct.data.Value().size() - encoding:NSUTF8StringEncoding]; + self.data = AsString(decodableStruct.data.Value()); + if (self.data == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + return err; + } } else { self.data = nil; } @@ -10839,9 +10865,11 @@ - (CHIP_ERROR)_setFieldsFromDecodableStruct: } { if (decodableStruct.data.HasValue()) { - self.data = [[NSString alloc] initWithBytes:decodableStruct.data.Value().data() - length:decodableStruct.data.Value().size() - encoding:NSUTF8StringEncoding]; + self.data = AsString(decodableStruct.data.Value()); + if (self.data == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + return err; + } } else { self.data = nil; } @@ -11095,7 +11123,7 @@ - (CHIP_ERROR)_setFieldsFromDecodableStruct: } { if (decodableStruct.data.HasValue()) { - self.data = [NSData dataWithBytes:decodableStruct.data.Value().data() length:decodableStruct.data.Value().size()]; + self.data = AsData(decodableStruct.data.Value()); } else { self.data = nil; } @@ -11209,9 +11237,11 @@ - (CHIP_ERROR)_setFieldsFromDecodableStruct: (const chip::app::Clusters::AccountLogin::Commands::GetSetupPINResponse::DecodableType &)decodableStruct { { - self.setupPIN = [[NSString alloc] initWithBytes:decodableStruct.setupPIN.data() - length:decodableStruct.setupPIN.size() - encoding:NSUTF8StringEncoding]; + self.setupPIN = AsString(decodableStruct.setupPIN); + if (self.setupPIN == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + return err; + } } return CHIP_NO_ERROR; } @@ -12058,10 +12088,12 @@ - (CHIP_ERROR)_setFieldsFromDecodableStruct: newElement_0.c.a = [NSNumber numberWithUnsignedChar:entry_0.c.a]; newElement_0.c.b = [NSNumber numberWithBool:entry_0.c.b]; newElement_0.c.c = [NSNumber numberWithUnsignedChar:chip::to_underlying(entry_0.c.c)]; - newElement_0.c.d = [NSData dataWithBytes:entry_0.c.d.data() length:entry_0.c.d.size()]; - newElement_0.c.e = [[NSString alloc] initWithBytes:entry_0.c.e.data() - length:entry_0.c.e.size() - encoding:NSUTF8StringEncoding]; + newElement_0.c.d = AsData(entry_0.c.d); + newElement_0.c.e = AsString(entry_0.c.e); + if (newElement_0.c.e == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + return err; + } newElement_0.c.f = [NSNumber numberWithUnsignedChar:entry_0.c.f.Raw()]; newElement_0.c.g = [NSNumber numberWithFloat:entry_0.c.g]; newElement_0.c.h = [NSNumber numberWithDouble:entry_0.c.h]; @@ -12075,10 +12107,12 @@ - (CHIP_ERROR)_setFieldsFromDecodableStruct: newElement_2.a = [NSNumber numberWithUnsignedChar:entry_2.a]; newElement_2.b = [NSNumber numberWithBool:entry_2.b]; newElement_2.c = [NSNumber numberWithUnsignedChar:chip::to_underlying(entry_2.c)]; - newElement_2.d = [NSData dataWithBytes:entry_2.d.data() length:entry_2.d.size()]; - newElement_2.e = [[NSString alloc] initWithBytes:entry_2.e.data() - length:entry_2.e.size() - encoding:NSUTF8StringEncoding]; + newElement_2.d = AsData(entry_2.d); + newElement_2.e = AsString(entry_2.e); + if (newElement_2.e == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + return err; + } newElement_2.f = [NSNumber numberWithUnsignedChar:entry_2.f.Raw()]; newElement_2.g = [NSNumber numberWithFloat:entry_2.g]; newElement_2.h = [NSNumber numberWithDouble:entry_2.h]; @@ -12111,7 +12145,7 @@ - (CHIP_ERROR)_setFieldsFromDecodableStruct: while (iter_2.Next()) { auto & entry_2 = iter_2.GetValue(); NSData * newElement_2; - newElement_2 = [NSData dataWithBytes:entry_2.data() length:entry_2.size()]; + newElement_2 = AsData(entry_2); [array_2 addObject:newElement_2]; } CHIP_ERROR err = iter_2.GetStatus(); @@ -12155,10 +12189,12 @@ - (CHIP_ERROR)_setFieldsFromDecodableStruct: newElement_0.a = [NSNumber numberWithUnsignedChar:entry_0.a]; newElement_0.b = [NSNumber numberWithBool:entry_0.b]; newElement_0.c = [NSNumber numberWithUnsignedChar:chip::to_underlying(entry_0.c)]; - newElement_0.d = [NSData dataWithBytes:entry_0.d.data() length:entry_0.d.size()]; - newElement_0.e = [[NSString alloc] initWithBytes:entry_0.e.data() - length:entry_0.e.size() - encoding:NSUTF8StringEncoding]; + newElement_0.d = AsData(entry_0.d); + newElement_0.e = AsString(entry_0.e); + if (newElement_0.e == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + return err; + } newElement_0.f = [NSNumber numberWithUnsignedChar:entry_0.f.Raw()]; newElement_0.g = [NSNumber numberWithFloat:entry_0.g]; newElement_0.h = [NSNumber numberWithDouble:entry_0.h]; @@ -12886,9 +12922,11 @@ - (CHIP_ERROR)_setFieldsFromDecodableStruct: } { if (decodableStruct.nullableStringValue.HasValue()) { - self.nullableStringValue = [[NSString alloc] initWithBytes:decodableStruct.nullableStringValue.Value().data() - length:decodableStruct.nullableStringValue.Value().size() - encoding:NSUTF8StringEncoding]; + self.nullableStringValue = AsString(decodableStruct.nullableStringValue.Value()); + if (self.nullableStringValue == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + return err; + } } else { self.nullableStringValue = nil; } @@ -12898,9 +12936,11 @@ - (CHIP_ERROR)_setFieldsFromDecodableStruct: } { if (decodableStruct.optionalStringValue.HasValue()) { - self.optionalStringValue = [[NSString alloc] initWithBytes:decodableStruct.optionalStringValue.Value().data() - length:decodableStruct.optionalStringValue.Value().size() - encoding:NSUTF8StringEncoding]; + self.optionalStringValue = AsString(decodableStruct.optionalStringValue.Value()); + if (self.optionalStringValue == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + return err; + } } else { self.optionalStringValue = nil; } @@ -12917,10 +12957,11 @@ - (CHIP_ERROR)_setFieldsFromDecodableStruct: } { if (decodableStruct.nullableOptionalStringValue.HasValue()) { - self.nullableOptionalStringValue = - [[NSString alloc] initWithBytes:decodableStruct.nullableOptionalStringValue.Value().data() - length:decodableStruct.nullableOptionalStringValue.Value().size() - encoding:NSUTF8StringEncoding]; + self.nullableOptionalStringValue = AsString(decodableStruct.nullableOptionalStringValue.Value()); + if (self.nullableOptionalStringValue == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + return err; + } } else { self.nullableOptionalStringValue = nil; } @@ -12935,11 +12976,12 @@ - (CHIP_ERROR)_setFieldsFromDecodableStruct: self.nullableStructValue.b = [NSNumber numberWithBool:decodableStruct.nullableStructValue.Value().b]; self.nullableStructValue.c = [NSNumber numberWithUnsignedChar:chip::to_underlying(decodableStruct.nullableStructValue.Value().c)]; - self.nullableStructValue.d = [NSData dataWithBytes:decodableStruct.nullableStructValue.Value().d.data() - length:decodableStruct.nullableStructValue.Value().d.size()]; - self.nullableStructValue.e = [[NSString alloc] initWithBytes:decodableStruct.nullableStructValue.Value().e.data() - length:decodableStruct.nullableStructValue.Value().e.size() - encoding:NSUTF8StringEncoding]; + self.nullableStructValue.d = AsData(decodableStruct.nullableStructValue.Value().d); + self.nullableStructValue.e = AsString(decodableStruct.nullableStructValue.Value().e); + if (self.nullableStructValue.e == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + return err; + } self.nullableStructValue.f = [NSNumber numberWithUnsignedChar:decodableStruct.nullableStructValue.Value().f.Raw()]; self.nullableStructValue.g = [NSNumber numberWithFloat:decodableStruct.nullableStructValue.Value().g]; self.nullableStructValue.h = [NSNumber numberWithDouble:decodableStruct.nullableStructValue.Value().h]; @@ -12957,11 +12999,12 @@ - (CHIP_ERROR)_setFieldsFromDecodableStruct: self.optionalStructValue.b = [NSNumber numberWithBool:decodableStruct.optionalStructValue.Value().b]; self.optionalStructValue.c = [NSNumber numberWithUnsignedChar:chip::to_underlying(decodableStruct.optionalStructValue.Value().c)]; - self.optionalStructValue.d = [NSData dataWithBytes:decodableStruct.optionalStructValue.Value().d.data() - length:decodableStruct.optionalStructValue.Value().d.size()]; - self.optionalStructValue.e = [[NSString alloc] initWithBytes:decodableStruct.optionalStructValue.Value().e.data() - length:decodableStruct.optionalStructValue.Value().e.size() - encoding:NSUTF8StringEncoding]; + self.optionalStructValue.d = AsData(decodableStruct.optionalStructValue.Value().d); + self.optionalStructValue.e = AsString(decodableStruct.optionalStructValue.Value().e); + if (self.optionalStructValue.e == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + return err; + } self.optionalStructValue.f = [NSNumber numberWithUnsignedChar:decodableStruct.optionalStructValue.Value().f.Raw()]; self.optionalStructValue.g = [NSNumber numberWithFloat:decodableStruct.optionalStructValue.Value().g]; self.optionalStructValue.h = [NSNumber numberWithDouble:decodableStruct.optionalStructValue.Value().h]; @@ -12987,13 +13030,12 @@ - (CHIP_ERROR)_setFieldsFromDecodableStruct: self.nullableOptionalStructValue.b = [NSNumber numberWithBool:decodableStruct.nullableOptionalStructValue.Value().b]; self.nullableOptionalStructValue.c = [NSNumber numberWithUnsignedChar:chip::to_underlying(decodableStruct.nullableOptionalStructValue.Value().c)]; - self.nullableOptionalStructValue.d = - [NSData dataWithBytes:decodableStruct.nullableOptionalStructValue.Value().d.data() - length:decodableStruct.nullableOptionalStructValue.Value().d.size()]; - self.nullableOptionalStructValue.e = - [[NSString alloc] initWithBytes:decodableStruct.nullableOptionalStructValue.Value().e.data() - length:decodableStruct.nullableOptionalStructValue.Value().e.size() - encoding:NSUTF8StringEncoding]; + self.nullableOptionalStructValue.d = AsData(decodableStruct.nullableOptionalStructValue.Value().d); + self.nullableOptionalStructValue.e = AsString(decodableStruct.nullableOptionalStructValue.Value().e); + if (self.nullableOptionalStructValue.e == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + return err; + } self.nullableOptionalStructValue.f = [NSNumber numberWithUnsignedChar:decodableStruct.nullableOptionalStructValue.Value().f.Raw()]; self.nullableOptionalStructValue.g = [NSNumber numberWithFloat:decodableStruct.nullableOptionalStructValue.Value().g]; @@ -13315,10 +13357,12 @@ - (CHIP_ERROR)_setFieldsFromDecodableStruct: self.arg1.a = [NSNumber numberWithUnsignedChar:decodableStruct.arg1.a]; self.arg1.b = [NSNumber numberWithBool:decodableStruct.arg1.b]; self.arg1.c = [NSNumber numberWithUnsignedChar:chip::to_underlying(decodableStruct.arg1.c)]; - self.arg1.d = [NSData dataWithBytes:decodableStruct.arg1.d.data() length:decodableStruct.arg1.d.size()]; - self.arg1.e = [[NSString alloc] initWithBytes:decodableStruct.arg1.e.data() - length:decodableStruct.arg1.e.size() - encoding:NSUTF8StringEncoding]; + self.arg1.d = AsData(decodableStruct.arg1.d); + self.arg1.e = AsString(decodableStruct.arg1.e); + if (self.arg1.e == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + return err; + } self.arg1.f = [NSNumber numberWithUnsignedChar:decodableStruct.arg1.f.Raw()]; self.arg1.g = [NSNumber numberWithFloat:decodableStruct.arg1.g]; self.arg1.h = [NSNumber numberWithDouble:decodableStruct.arg1.h]; diff --git a/src/darwin/Framework/CHIP/zap-generated/MTREventTLVValueDecoder.mm b/src/darwin/Framework/CHIP/zap-generated/MTREventTLVValueDecoder.mm index 416a23a1e5825f..d0767405aa8352 100644 --- a/src/darwin/Framework/CHIP/zap-generated/MTREventTLVValueDecoder.mm +++ b/src/darwin/Framework/CHIP/zap-generated/MTREventTLVValueDecoder.mm @@ -18,6 +18,8 @@ #import "MTREventTLVValueDecoder_Internal.h" #import "MTRStructsObjc.h" +#import "NSDataSpanConversion.h" +#import "NSStringSpanConversion.h" #include #include @@ -291,8 +293,7 @@ static id _Nullable DecodeEventPayloadForAccessControlCluster(EventId aEventId, memberValue = nil; } else { memberValue = [MTRAccessControlClusterAccessControlExtensionStruct new]; - memberValue.data = [NSData dataWithBytes:cppValue.latestValue.Value().data.data() - length:cppValue.latestValue.Value().data.size()]; + memberValue.data = AsData(cppValue.latestValue.Value().data); memberValue.fabricIndex = [NSNumber numberWithUnsignedChar:cppValue.latestValue.Value().fabricIndex]; } value.latestValue = memberValue; @@ -1045,9 +1046,12 @@ static id _Nullable DecodeEventPayloadForSoftwareDiagnosticsCluster(EventId aEve do { NSString * _Nullable memberValue; if (cppValue.name.HasValue()) { - memberValue = [[NSString alloc] initWithBytes:cppValue.name.Value().data() - length:cppValue.name.Value().size() - encoding:NSUTF8StringEncoding]; + memberValue = AsString(cppValue.name.Value()); + if (memberValue == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + *aError = err; + return nil; + } } else { memberValue = nil; } @@ -1056,8 +1060,7 @@ static id _Nullable DecodeEventPayloadForSoftwareDiagnosticsCluster(EventId aEve do { NSData * _Nullable memberValue; if (cppValue.faultRecording.HasValue()) { - memberValue = [NSData dataWithBytes:cppValue.faultRecording.Value().data() - length:cppValue.faultRecording.Value().size()]; + memberValue = AsData(cppValue.faultRecording.Value()); } else { memberValue = nil; } @@ -3199,10 +3202,13 @@ static id _Nullable DecodeEventPayloadForUnitTestingCluster(EventId aEventId, TL memberValue.a = [NSNumber numberWithUnsignedChar:cppValue.arg4.a]; memberValue.b = [NSNumber numberWithBool:cppValue.arg4.b]; memberValue.c = [NSNumber numberWithUnsignedChar:chip::to_underlying(cppValue.arg4.c)]; - memberValue.d = [NSData dataWithBytes:cppValue.arg4.d.data() length:cppValue.arg4.d.size()]; - memberValue.e = [[NSString alloc] initWithBytes:cppValue.arg4.e.data() - length:cppValue.arg4.e.size() - encoding:NSUTF8StringEncoding]; + memberValue.d = AsData(cppValue.arg4.d); + memberValue.e = AsString(cppValue.arg4.e); + if (memberValue.e == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + *aError = err; + return nil; + } memberValue.f = [NSNumber numberWithUnsignedChar:cppValue.arg4.f.Raw()]; memberValue.g = [NSNumber numberWithFloat:cppValue.arg4.g]; memberValue.h = [NSNumber numberWithDouble:cppValue.arg4.h]; @@ -3220,10 +3226,13 @@ static id _Nullable DecodeEventPayloadForUnitTestingCluster(EventId aEventId, TL newElement_0.a = [NSNumber numberWithUnsignedChar:entry_0.a]; newElement_0.b = [NSNumber numberWithBool:entry_0.b]; newElement_0.c = [NSNumber numberWithUnsignedChar:chip::to_underlying(entry_0.c)]; - newElement_0.d = [NSData dataWithBytes:entry_0.d.data() length:entry_0.d.size()]; - newElement_0.e = [[NSString alloc] initWithBytes:entry_0.e.data() - length:entry_0.e.size() - encoding:NSUTF8StringEncoding]; + newElement_0.d = AsData(entry_0.d); + newElement_0.e = AsString(entry_0.e); + if (newElement_0.e == nil) { + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + *aError = err; + return nil; + } newElement_0.f = [NSNumber numberWithUnsignedChar:entry_0.f.Raw()]; newElement_0.g = [NSNumber numberWithFloat:entry_0.g]; newElement_0.h = [NSNumber numberWithDouble:entry_0.h];