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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
// Copyright 2023 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
////////////////////////////////////////////////////////////////////////////////
#include "tink/internal/serialization_test_util.h"
#include <string_view>
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "absl/types/optional.h"
#include "tink/insecure_secret_key_access.h"
#include "tink/parameters.h"
#include "tink/util/statusor.h"
#include "tink/util/test_matchers.h"
namespace crypto {
namespace tink {
namespace internal {
namespace {
using ::crypto::tink::test::IsOkAndHolds;
using ::testing::Eq;
using ::testing::IsFalse;
using ::testing::IsTrue;
using ::testing::Not;
TEST(SerializationTest, Create) {
EXPECT_THAT(BaseSerialization("base_type_url").ObjectIdentifier(),
Eq("base_type_url"));
EXPECT_THAT(NoIdSerialization().ObjectIdentifier(), Eq(kNoIdTypeUrl));
EXPECT_THAT(IdParamsSerialization().ObjectIdentifier(), Eq(kIdTypeUrl));
IdKeySerialization id_key(123);
EXPECT_THAT(id_key.ObjectIdentifier(), Eq(kIdTypeUrl));
EXPECT_THAT(id_key.GetKeyId(), Eq(123));
}
TEST(NoIdParamsTest, Create) {
NoIdParams params;
EXPECT_THAT(params.HasIdRequirement(), IsFalse());
EXPECT_THAT(params, Eq(NoIdParams()));
EXPECT_THAT(params, Not(Eq(IdParams())));
}
TEST(NoIdParamsTest, ParseAndSerialize) {
EXPECT_THAT(ParseNoIdParams(NoIdSerialization()), IsOkAndHolds(NoIdParams()));
EXPECT_THAT(SerializeNoIdParams(NoIdParams()),
IsOkAndHolds(NoIdSerialization()));
}
TEST(IdParamsTest, Create) {
IdParams params;
EXPECT_THAT(params.HasIdRequirement(), IsTrue());
EXPECT_THAT(params, Eq(IdParams()));
EXPECT_THAT(params, Not(Eq(NoIdParams())));
}
TEST(IdParamsTest, ParseAndSerialize) {
EXPECT_THAT(ParseIdParams(IdParamsSerialization()), IsOkAndHolds(IdParams()));
EXPECT_THAT(SerializeIdParams(IdParams()),
IsOkAndHolds(IdParamsSerialization()));
}
TEST(NoIdKeyTest, Create) {
NoIdKey key;
EXPECT_THAT(key.GetIdRequirement(), Eq(absl::nullopt));
EXPECT_THAT(key.GetParameters(), Eq(NoIdParams()));
EXPECT_THAT(key, Eq(NoIdKey()));
EXPECT_THAT(key, Not(Eq(IdKey(123))));
}
TEST(NoIdKeyTest, ParseAndSerialize) {
EXPECT_THAT(ParseNoIdKey(NoIdSerialization(), InsecureSecretKeyAccess::Get()),
IsOkAndHolds(NoIdKey()));
EXPECT_THAT(SerializeNoIdKey(NoIdKey(), InsecureSecretKeyAccess::Get()),
IsOkAndHolds(NoIdSerialization()));
}
TEST(IdKeyTest, Create) {
IdKey key(123);
EXPECT_THAT(key.GetIdRequirement(), Eq(123));
EXPECT_THAT(key.GetParameters(), Eq(IdParams()));
EXPECT_THAT(key, Eq(IdKey(123)));
EXPECT_THAT(key, Not(Eq(IdKey(456))));
EXPECT_THAT(key, Not(Eq(NoIdKey())));
}
TEST(IdKeyTest, ParseAndSerialize) {
EXPECT_THAT(ParseIdKey(IdKeySerialization(123),
InsecureSecretKeyAccess::Get()),
IsOkAndHolds(IdKey(123)));
EXPECT_THAT(SerializeIdKey(IdKey(123), InsecureSecretKeyAccess::Get()),
IsOkAndHolds(IdKeySerialization(123)));
}
} // namespace
} // namespace internal
} // namespace tink
} // namespace crypto
|