1   /*
2    * Copyright 2025 LINE Corporation
3    *
4    * LINE Corporation licenses this file to you under the Apache License,
5    * version 2.0 (the "License"); you may not use this file except in compliance
6    * with the License. You may obtain a copy of the License at:
7    *
8    *   https://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, WITHOUT
12   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13   * License for the specific language governing permissions and limitations
14   * under the License.
15   */
16  package com.linecorp.centraldogma.server.internal.api.sysadmin;
17  
18  import static com.google.common.base.MoreObjects.toStringHelper;
19  import static com.google.common.base.Preconditions.checkArgument;
20  import static java.time.format.DateTimeFormatter.ISO_INSTANT;
21  import static java.util.Objects.requireNonNull;
22  
23  import java.time.Instant;
24  
25  import com.fasterxml.jackson.annotation.JsonCreator;
26  import com.fasterxml.jackson.annotation.JsonProperty;
27  
28  /**
29   * Data transfer object (DTO) for a session master key.
30   * Sensitive information such as the key material or salt is not included.
31   */
32  public final class SessionMasterKeyDto {
33  
34      private final int version;
35      private final String kekId;
36      private final String creation;
37  
38      /**
39       * Creates a new instance.
40       */
41      @JsonCreator
42      public SessionMasterKeyDto(@JsonProperty("version") int version,
43                                 @JsonProperty("kekId") String kekId,
44                                 @JsonProperty("creation") Instant creation) {
45          checkArgument(version > 0, "version must be positive: %s", version);
46          this.version = version;
47          this.kekId = requireNonNull(kekId, "kekId");
48          this.creation = ISO_INSTANT.format(requireNonNull(creation, "creation"));
49      }
50  
51      /**
52       * Returns the version of the session master key.
53       */
54      @JsonProperty
55      public int version() {
56          return version;
57      }
58  
59      /**
60       * Returns the key encryption key (KEK) ID used to wrap the session master key.
61       */
62      @JsonProperty
63      public String kekId() {
64          return kekId;
65      }
66  
67      /**
68       * Returns the creation timestamp of the session master key.
69       */
70      @JsonProperty
71      public String creation() {
72          return creation;
73      }
74  
75      @Override
76      public String toString() {
77          return toStringHelper(this).add("version", version)
78                                     .add("kekId", kekId)
79                                     .add("creation", creation)
80                                     .toString();
81      }
82  }