|
| 1 | +/* |
| 2 | + * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except |
| 5 | + * in compliance with the License. A copy of the License is located at |
| 6 | + * |
| 7 | + * http://aws.amazon.com/apache2.0 |
| 8 | + * |
| 9 | + * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, |
| 10 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
| 11 | + * specific language governing permissions and limitations under the License. |
| 12 | + */ |
| 13 | + |
| 14 | +package com.amazonaws.encryptionsdk.keyrings; |
| 15 | + |
| 16 | +import org.apache.commons.lang3.builder.ToStringBuilder; |
| 17 | +import org.apache.commons.lang3.builder.ToStringStyle; |
| 18 | + |
| 19 | +import java.util.Collections; |
| 20 | +import java.util.Objects; |
| 21 | +import java.util.Set; |
| 22 | + |
| 23 | +import static org.apache.commons.lang3.Validate.notBlank; |
| 24 | +import static org.apache.commons.lang3.Validate.notEmpty; |
| 25 | + |
| 26 | +/** |
| 27 | + * A representation of an action that a keyring has taken on a data key. |
| 28 | + */ |
| 29 | +public class KeyringTraceEntry { |
| 30 | + |
| 31 | + private final String keyNamespace; |
| 32 | + private final String keyName; |
| 33 | + private final Set<KeyringTraceFlag> flags; |
| 34 | + |
| 35 | + /** |
| 36 | + * Constructs a new `KeyringTraceEntry`. |
| 37 | + * |
| 38 | + * @param keyNamespace The namespace for the key. |
| 39 | + * @param keyName The name of the key. |
| 40 | + * @param flags A set of one or more KeyringTraceFlag enums |
| 41 | + * indicating what actions were taken by a keyring. |
| 42 | + */ |
| 43 | + KeyringTraceEntry(final String keyNamespace, final String keyName, final Set<KeyringTraceFlag> flags) { |
| 44 | + notBlank(keyNamespace, "keyNamespace is required"); |
| 45 | + notBlank(keyName, "keyName is required"); |
| 46 | + notEmpty(flags, "At least one flag is required"); |
| 47 | + |
| 48 | + this.keyNamespace = keyNamespace; |
| 49 | + this.keyName = keyName; |
| 50 | + this.flags = Collections.unmodifiableSet(flags); |
| 51 | + } |
| 52 | + |
| 53 | + /** |
| 54 | + * Returns the key namespace. |
| 55 | + * |
| 56 | + * @return The key namespace. |
| 57 | + */ |
| 58 | + public String getKeyNamespace() { |
| 59 | + return this.keyNamespace; |
| 60 | + } |
| 61 | + |
| 62 | + /** |
| 63 | + * Returns the key name. |
| 64 | + * |
| 65 | + * @return The key name. |
| 66 | + */ |
| 67 | + public String getKeyName() { |
| 68 | + return this.keyName; |
| 69 | + } |
| 70 | + |
| 71 | + /** |
| 72 | + * Returns an unmodifiable set of flags that indicate |
| 73 | + * which actions were taken by a keyring. |
| 74 | + * |
| 75 | + * @return The unmodifiable set of flags. |
| 76 | + */ |
| 77 | + public Set<KeyringTraceFlag> getFlags() { |
| 78 | + return this.flags; |
| 79 | + } |
| 80 | + |
| 81 | + @Override |
| 82 | + public boolean equals(Object o) { |
| 83 | + if (this == o) return true; |
| 84 | + if (o == null || getClass() != o.getClass()) return false; |
| 85 | + KeyringTraceEntry that = (KeyringTraceEntry) o; |
| 86 | + return Objects.equals(keyNamespace, that.keyNamespace) && |
| 87 | + Objects.equals(keyName, that.keyName) && |
| 88 | + Objects.equals(flags, that.flags); |
| 89 | + } |
| 90 | + |
| 91 | + @Override |
| 92 | + public int hashCode() { |
| 93 | + return Objects.hash(keyNamespace, keyName, flags); |
| 94 | + } |
| 95 | + |
| 96 | + @Override |
| 97 | + public String toString() { |
| 98 | + return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE) |
| 99 | + .append("keyNamespace", this.keyNamespace) |
| 100 | + .append("keyName", this.keyName) |
| 101 | + .append("flags", this.flags) |
| 102 | + .toString(); |
| 103 | + } |
| 104 | +} |
0 commit comments