001/*
002 * Copyright 2022-2026 Revetware LLC.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package com.soklet;
018
019import org.jspecify.annotations.NonNull;
020import org.jspecify.annotations.Nullable;
021
022import javax.annotation.concurrent.ThreadSafe;
023import java.util.Set;
024
025import static java.util.Objects.requireNonNull;
026
027/**
028 * Immutable, secret-free atomic snapshot of a live MCP protection keyring.
029 *
030 * @author <a href="https://www.revetkn.com">Mark Allen</a>
031 */
032@ThreadSafe
033public final class McpProtectionKeyringSnapshot {
034        @NonNull
035        private final String activeKeyId;
036        @NonNull
037        private final Set<@NonNull String> verificationKeyIds;
038        @NonNull
039        private final McpProtectionKeyringFingerprint fingerprint;
040
041        McpProtectionKeyringSnapshot(@NonNull String activeKeyId,
042                        @NonNull Set<@NonNull String> verificationKeyIds,
043                        @NonNull McpProtectionKeyringFingerprint fingerprint) {
044                this.activeKeyId = requireNonNull(activeKeyId);
045                this.verificationKeyIds = Set.copyOf(verificationKeyIds);
046                this.fingerprint = requireNonNull(fingerprint);
047        }
048
049        /** @return non-secret active key ID */
050        @NonNull
051        public String getActiveKeyId() {
052                return this.activeKeyId;
053        }
054
055        /** @return immutable verification-only key ID set */
056        @NonNull
057        public Set<@NonNull String> getVerificationKeyIds() {
058                return this.verificationKeyIds;
059        }
060
061        /** @return fingerprint for the complete captured ring */
062        @NonNull
063        public McpProtectionKeyringFingerprint getFingerprint() {
064                return this.fingerprint;
065        }
066
067        /** @return whether every captured keyring property is structurally equal */
068        @Override
069        public boolean equals(@Nullable Object other) {
070                return this == other
071                                || other instanceof McpProtectionKeyringSnapshot snapshot
072                                && this.activeKeyId.equals(snapshot.activeKeyId)
073                                && this.verificationKeyIds.equals(snapshot.verificationKeyIds)
074                                && this.fingerprint.equals(snapshot.fingerprint);
075        }
076
077        /** @return structural keyring-snapshot hash code */
078        @Override
079        public int hashCode() {
080                int result = this.activeKeyId.hashCode();
081                result = 31 * result + this.verificationKeyIds.hashCode();
082                result = 31 * result + this.fingerprint.hashCode();
083                return result;
084        }
085}