1 /*
2  * Copyright 2014-2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
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  * A copy of the License is located at
7  *
8  *  http://aws.amazon.com/apache2.0
9  *
10  * or in the "license" file accompanying this file. This file is distributed
11  * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12  * express or implied. See the License for the specific language governing
13  * permissions and limitations under the License.
14  */

15 package com.amazonaws.auth.internal;
16
17 import com.amazonaws.annotation.Immutable;
18
19 /**
20  * Holds the signing key and the number of days since epoch for the date for
21  * which the signing key was generated.
22  */

23 @Immutable
24 public final class SignerKey {
25
26     private final long numberOfDaysSinceEpoch;
27
28     private final byte[] signingKey;
29
30     public SignerKey(long numberOfDaysSinceEpoch, byte[] signingKey) {
31         if (numberOfDaysSinceEpoch <= 0L) {
32             throw new IllegalArgumentException(
33                     "Not able to cache signing key. Signing date to be cached is invalid");
34         }
35         if (signingKey == null) {
36             throw new IllegalArgumentException(
37                     "Not able to cache signing key. Signing Key to be cached are null");
38         }
39         this.numberOfDaysSinceEpoch = numberOfDaysSinceEpoch;
40         this.signingKey = signingKey.clone();
41     }
42
43     /**
44      * Returns the number of days since epoch for the date used for generating
45      * signing key.
46      */

47     public long getNumberOfDaysSinceEpoch() {
48         return numberOfDaysSinceEpoch;
49     }
50
51     /**
52      * Returns a copy of the signing key.
53      */

54     public byte[] getSigningKey() {
55         return signingKey.clone();
56     }
57 }
58