aboutsummaryrefslogtreecommitdiffstats
path: root/container-disc/src/main/java/com/yahoo/container/jdisc/secret/Secret.java
blob: fef0ba804eb6fe6a50489e8159a773b4e0d0119d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package com.yahoo.container.jdisc.secret;

import com.yahoo.security.YBase64;
import com.yahoo.text.Utf8;

import java.util.Arrays;
import java.util.Objects;

public class Secret {

    private final Key key;
    private final byte[] secret;
    private final int version;

    public Secret(Key key, byte[] secret, int version) {
        this.key = key;
        this.secret = secret;
        this.version = version;
    }

    public String keyGroup() {
        return key.keyGroup();
    }

    public String keyName() {
        return key.keyName();
    }

    public byte[] secret() {
        return secret;
    }

    public String secretAsString() { return Utf8.toString(secret); }

    /** @return secret value for keys that are auto-rotated by CKMS */
    public byte[] secretAsYbase64Decoded() { return YBase64.decode(secret); }

    public int version() {
        return version;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Secret that = (Secret) o;
        if ( ! (that.key.equals(key))) return false;
        if ( ! (Arrays.equals(that.secret, secret))) return false;
        if (that.version != (version)) return false;
        return true;
    }

    @Override
    public int hashCode() {
        return Objects.hash(key, version, Arrays.hashCode(secret));
    }

}