• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 package com.android.adservices.cobalt;
17 
18 import static com.android.adservices.cobalt.CobaltConstants.DEFAULT_API_KEY;
19 
20 import com.google.common.io.BaseEncoding;
21 import com.google.protobuf.ByteString;
22 
23 import java.util.Objects;
24 
25 /** Static data and functions related to Cobalt API keys. */
26 public final class CobaltApiKeys {
27     /** Copy an API key from a base-16 encoded hex string. */
copyFromHexApiKey(String apiKey)28     static ByteString copyFromHexApiKey(String apiKey) {
29         Objects.requireNonNull(apiKey);
30         return apiKey.equals(DEFAULT_API_KEY)
31                 ? ByteString.copyFromUtf8(apiKey)
32                 : ByteString.copyFrom(BaseEncoding.base16().lowerCase().decode(apiKey));
33     }
34 
CobaltApiKeys()35     private CobaltApiKeys() {
36         throw new UnsupportedOperationException("Contains only static members");
37     }
38 }
39