1 /* 2 * Copyright (C) 2024 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.kanon; 18 19 import androidx.annotation.NonNull; 20 import androidx.room.ColumnInfo; 21 import androidx.room.Entity; 22 import androidx.room.PrimaryKey; 23 import androidx.room.TypeConverters; 24 25 import com.android.adservices.data.common.FledgeRoomConverters; 26 27 import com.google.auto.value.AutoValue; 28 import com.google.auto.value.AutoValue.CopyAnnotations; 29 30 import java.time.Instant; 31 32 @Entity(tableName = DBServerParameters.TABLE_NAME) 33 @TypeConverters({FledgeRoomConverters.class}) 34 @AutoValue 35 @CopyAnnotations 36 public abstract class DBServerParameters { 37 public static final String TABLE_NAME = "server_parameters"; 38 39 /** Sever public parameters version. */ 40 @NonNull 41 @ColumnInfo(name = "server_public_parameters", typeAffinity = ColumnInfo.BLOB) 42 @CopyAnnotations 43 @SuppressWarnings({"AutoValueImmutableFields", "AutoValueMutable"}) getServerPublicParameters()44 public abstract byte[] getServerPublicParameters(); 45 46 /** Sever parameter JOIN expiry, this field is returned in the GetSeverParametersResponse. */ 47 @NonNull 48 @CopyAnnotations 49 @ColumnInfo(name = "server_params_join_expiry_instant") getServerParamsJoinExpiryInstant()50 public abstract Instant getServerParamsJoinExpiryInstant(); 51 52 /** Sever parameter SIGN expiry, this field is returned in the GetSeverParametersResponse. */ 53 @NonNull 54 @CopyAnnotations 55 @ColumnInfo(name = "server_params_sign_expiry_instant") getServerParamsSignExpiryInstant()56 public abstract Instant getServerParamsSignExpiryInstant(); 57 58 /** Creation instant. Timestamp when the server parameters where created */ 59 @NonNull 60 @CopyAnnotations 61 @PrimaryKey 62 @ColumnInfo(name = "creation_instant", defaultValue = "CURRENT_TIMESTAMP") getCreationInstant()63 public abstract Instant getCreationInstant(); 64 65 /** Sever parameter version, this field is returned in the GetSeverParametersResponse. */ 66 @CopyAnnotations 67 @NonNull 68 @ColumnInfo(name = "server_params_version") getServerParamsVersion()69 public abstract String getServerParamsVersion(); 70 71 /** Creates and returns a {@link DBServerParameters} object. */ create( @onNull String serverParamsVersion, @NonNull Instant creationInstant, @NonNull Instant serverParamsSignExpiryInstant, @NonNull Instant serverParamsJoinExpiryInstant, @NonNull byte[] serverPublicParameters)72 public static DBServerParameters create( 73 @NonNull String serverParamsVersion, 74 @NonNull Instant creationInstant, 75 @NonNull Instant serverParamsSignExpiryInstant, 76 @NonNull Instant serverParamsJoinExpiryInstant, 77 @NonNull byte[] serverPublicParameters) { 78 return builder() 79 .setServerPublicParameters(serverPublicParameters) 80 .setServerParamsVersion(serverParamsVersion) 81 .setCreationInstant(creationInstant) 82 .setServerParamsSignExpiryInstant(serverParamsSignExpiryInstant) 83 .setServerParamsJoinExpiryInstant(serverParamsJoinExpiryInstant) 84 .build(); 85 } 86 87 /** Returns a {@link DBServerParameters.Builder} for {@link DBServerParameters}. */ builder()88 public static DBServerParameters.Builder builder() { 89 return new AutoValue_DBServerParameters.Builder(); 90 } 91 92 @AutoValue.Builder 93 public abstract static class Builder { 94 /** Sets the server parmas version. */ setServerParamsVersion(String serverParamsVersion)95 public abstract Builder setServerParamsVersion(String serverParamsVersion); 96 97 /** Sets the creation instant. */ setCreationInstant(Instant creationInstant)98 public abstract Builder setCreationInstant(Instant creationInstant); 99 100 /** Sets the server parmas sign expiry instant. */ setServerParamsSignExpiryInstant( Instant serverParamsSignExpiryInstant)101 public abstract Builder setServerParamsSignExpiryInstant( 102 Instant serverParamsSignExpiryInstant); 103 104 /** Sets the server parmas join expiry instant. */ setServerParamsJoinExpiryInstant( Instant serverParamsJoinExpiryInstant)105 public abstract Builder setServerParamsJoinExpiryInstant( 106 Instant serverParamsJoinExpiryInstant); 107 108 /** Sets the server public abstract parameters. */ setServerPublicParameters(byte[] serverPublicParameters)109 public abstract Builder setServerPublicParameters(byte[] serverPublicParameters); 110 111 /** Builds and return a {@link DBServerParameters} object */ build()112 public abstract DBServerParameters build(); 113 } 114 } 115