1 /* 2 * Copyright (C) 2023 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.adservices.data.adselection.datahandlers; 18 19 import com.android.adservices.ohttp.ObliviousHttpRequestContext; 20 import com.android.adservices.service.adselection.encryption.AdSelectionEncryptionKey; 21 22 import com.google.common.base.Preconditions; 23 24 import java.util.Objects; 25 26 /** Class to validate data handlers when they are used for persisting or reading from DB. */ 27 public class DBValidator { 28 29 /** Validate that the {@EncryptionContext} object can be writtent to DB. */ validateEncryptionContext(EncryptionContext encryptionContext)30 public static void validateEncryptionContext(EncryptionContext encryptionContext) { 31 ObliviousHttpRequestContext requestContext = encryptionContext.getOhttpRequestContext(); 32 Objects.requireNonNull(requestContext.keyConfig().serializeKeyConfigToBytes()); 33 Objects.requireNonNull(requestContext.encapsulatedSharedSecret().serializeToBytes()); 34 35 Preconditions.checkArgument( 36 encryptionContext.getAdSelectionEncryptionKeyType() 37 != AdSelectionEncryptionKey.AdSelectionEncryptionKeyType.UNASSIGNED); 38 } 39 40 /** Validate that the {@ReportingData} object can be written to the DB. */ validateReportingData(ReportingData reportingData)41 public static void validateReportingData(ReportingData reportingData) { 42 Objects.requireNonNull(reportingData.getBuyerWinReportingUri()); 43 Objects.requireNonNull(reportingData.getSellerWinReportingUri()); 44 } 45 } 46