Skip to content
This repository has been archived by the owner on Apr 17, 2024. It is now read-only.

Commit

Permalink
Adding a version number constant consistent across languages.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 213049325
GitOrigin-RevId: 87533b41a95cd0dcef5d1d29d285e6fe14103cb1
  • Loading branch information
przydatek authored and Tink Team committed Sep 20, 2018
1 parent 61aa419 commit 30f9a0f
Show file tree
Hide file tree
Showing 19 changed files with 365 additions and 28 deletions.
4 changes: 4 additions & 0 deletions BUILD.bazel
Expand Up @@ -19,3 +19,7 @@ gazelle(
prefix = "github.com/google/tink",
)

filegroup(
name = "tink_version",
srcs = ["tink_version.bzl"],
)
33 changes: 33 additions & 0 deletions cc/BUILD.bazel
Expand Up @@ -2,6 +2,9 @@ package(default_visibility = ["//tools/build_defs:internal_pkg"])

licenses(["notice"]) # Apache 2.0

load("//:tink_version.bzl", "TINK_VERSION_LABEL")
load("//tools:common.bzl", "template_rule")

# public libraries

PUBLIC_APIS = [
Expand Down Expand Up @@ -39,6 +42,7 @@ PUBLIC_APIS = [
"signature_config.h",
"signature_key_templates.h",
"tink_config.h",
"version.h",
]

PUBLIC_API_DEPS = [
Expand All @@ -60,6 +64,7 @@ PUBLIC_API_DEPS = [
":mac",
":primitive_set",
":registry",
":version",
"//cc/aead:aead_config",
"//cc/aead:aead_factory",
"//cc/aead:aead_key_templates",
Expand Down Expand Up @@ -339,6 +344,23 @@ cc_library(
],
)

template_rule(
name = "version_h",
src = "version.h.templ",
out = "version.h",
substitutions = {
"TINK_VERSION_LABEL": "%s" % TINK_VERSION_LABEL,
},
)

cc_library(
name = "version",
srcs = ["core/version.cc"],
hdrs = [":version_h"],
include_prefix = "tink",
strip_include_prefix = "/cc",
)

cc_library(
name = "keyset_handle_hdr",
srcs = ["keyset_handle.h"],
Expand Down Expand Up @@ -597,6 +619,17 @@ cc_test(
],
)

cc_test(
name = "version_test",
size = "small",
srcs = ["core/version_test.cc"],
copts = ["-Iexternal/gtest/include"],
deps = [
":version",
"@com_google_googletest//:gtest_main",
],
)

cc_test(
name = "binary_keyset_reader_test",
size = "small",
Expand Down
25 changes: 25 additions & 0 deletions cc/core/version.cc
@@ -0,0 +1,25 @@
// Copyright 2018 Google Inc.
//
// 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/version.h"

namespace crypto {
namespace tink {

constexpr char Version::kTinkVersion[];

} // namespace tink
} // namespace crypto
45 changes: 45 additions & 0 deletions cc/core/version_test.cc
@@ -0,0 +1,45 @@
// Copyright 2018 Google Inc.
//
// 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/version.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"

namespace crypto {
namespace tink {
namespace {

TEST(VersionTest, testVersionFormat) {
// The regex represents Semantic Versioning syntax (www.semver.org),
// i.e. three dot-separated numbers, with an optional suffix
// that starts with a hyphen, to cover alpha/beta releases and
// release candiates, for example:
// 1.2.3
// 1.2.3-beta
// 1.2.3-RC1
std::string version_regex = "[0-9]+[.][0-9]+[.][0-9]+(-[A-Za-z0-9]+)?";
EXPECT_THAT(Version::kTinkVersion, testing::MatchesRegex(version_regex));
}

} // namespace
} // namespace tink
} // namespace crypto


int main(int ac, char* av[]) {
testing::InitGoogleTest(&ac, av);
return RUN_ALL_TESTS();
}
3 changes: 2 additions & 1 deletion cc/subtle/ecdsa_verify_boringssl_test.cc
Expand Up @@ -16,6 +16,7 @@

#include "tink/subtle/ecdsa_verify_boringssl.h"

#include <iostream>
#include <string>

#include "absl/strings/str_cat.h"
Expand Down Expand Up @@ -173,7 +174,7 @@ bool TestSignatures(const std::string& filename, bool allow_skipping,
std::string curve = test_group["key"]["curve"].GetString();
if (allow_skipping) {
std::cout << "Could not construct verifier for curve " << curve
<< verifier_result.status();
<< verifier_result.status();
} else {
ADD_FAILURE() << "Could not construct verifier for curve " << curve
<< verifier_result.status();
Expand Down
2 changes: 2 additions & 0 deletions cc/subtle/ecies_hkdf_sender_kem_boringssl_test.cc
Expand Up @@ -14,6 +14,8 @@
//
////////////////////////////////////////////////////////////////////////////////

#include <iostream>

#include "tink/subtle/ecies_hkdf_sender_kem_boringssl.h"
#include "tink/subtle/common_enums.h"
#include "tink/subtle/ecies_hkdf_recipient_kem_boringssl.h"
Expand Down
3 changes: 2 additions & 1 deletion cc/subtle/rsa_ssa_pkcs1_verify_boringssl_test.cc
Expand Up @@ -16,6 +16,7 @@

#include "tink/subtle/rsa_ssa_pkcs1_verify_boringssl.h"

#include <iostream>
#include <string>

#include "gtest/gtest.h"
Expand Down Expand Up @@ -209,7 +210,7 @@ bool TestSignatures(const std::string& filename, bool allow_skipping) {
std::string type = test_group["type"].GetString();
if (allow_skipping) {
std::cout << "Could not construct verifier for " << type << " group "
<< group_count << ": " << verifier_result.status();
<< group_count << ": " << verifier_result.status();
} else {
ADD_FAILURE() << "Could not construct verifier for " << type
<< " group " << group_count << ": "
Expand Down
31 changes: 31 additions & 0 deletions cc/version.h.templ
@@ -0,0 +1,31 @@
// Copyright 2018 Google Inc.
//
// 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.
//
///////////////////////////////////////////////////////////////////////////////

#ifndef TINK_VERSION_H_
#define TINK_VERSION_H_

namespace crypto {
namespace tink {

class Version {
public:
static constexpr char kTinkVersion[] = "TINK_VERSION_LABEL";
};

} // namespace tink
} // namespace crypto

#endif // TINK_VERSION_H_
23 changes: 15 additions & 8 deletions java/src/main/java/com/google/crypto/tink/BUILD.bazel
Expand Up @@ -3,6 +3,8 @@ licenses(["notice"]) # Apache 2.0
package(default_visibility = ["//tools/build_defs:internal_pkg"])

load("//tools/build_defs:javac.bzl", "JAVACOPTS_OSS")
load("//:tink_version.bzl", "TINK_VERSION_LABEL")
load("//tools:common.bzl", "template_rule")

full_protos = [
"//proto:common_java_proto",
Expand Down Expand Up @@ -53,11 +55,18 @@ filegroup(
filegroup(
name = "srcs",
srcs = glob(
[
"*.java",
],
["*.java"],
exclude = CLEARTEXT_KEYSET_HANDLE_SRCS,
),
) + [":version_java"],
)

template_rule(
name = "version_java",
src = "Version.java.templ",
out = "Version.java",
substitutions = {
"TINK_VERSION_LABEL": "%s" % TINK_VERSION_LABEL,
},
)

java_library(
Expand All @@ -76,15 +85,13 @@ java_library(
filegroup(
name = "android_srcs",
srcs = glob(
[
"*.java",
],
["*.java"],
exclude = CLEARTEXT_KEYSET_HANDLE_SRCS + [
# TextFormat doesn't work with lite protos
"TextFormatKeysetReaders.java",
"TextFormatKeysetWriters.java",
],
),
) + [":version_java"],
)

java_library(
Expand Down
29 changes: 29 additions & 0 deletions java/src/main/java/com/google/crypto/tink/Version.java.templ
@@ -0,0 +1,29 @@
// Copyright 2018 Google Inc.
//
// 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.
//
////////////////////////////////////////////////////////////////////////////////

package com.google.crypto.tink;

/**
* Version of the Tink library.
*
* @since 1.2.1
*/
public final class Version {
/**
* Version of the current Tink release.
*/
public static final String TINK_VERSION = "TINK_VERSION_LABEL";
}
40 changes: 40 additions & 0 deletions java/src/test/java/com/google/crypto/tink/VersionTest.java
@@ -0,0 +1,40 @@
// Copyright 2018 Google Inc.
//
// 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.
//
////////////////////////////////////////////////////////////////////////////////

package com.google.crypto.tink;

import static com.google.common.truth.Truth.assertThat;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

/** Tests for Version. */
@RunWith(JUnit4.class)
public class VersionTest {
@Test
public void testVersionFormat() throws Exception {
// The regex represents Semantic Versioning syntax (www.semver.org),
// i.e. three dot-separated numbers, with an optional suffix
// that starts with a hyphen, to cover alpha/beta releases and
// release candiates, for example:
// 1.2.3
// 1.2.3-beta
// 1.2.3-RC1
String versionRegex = "[0-9]+[.][0-9]+[.][0-9]+(-[A-Za-z0-9]+)?";
assertThat(Version.TINK_VERSION).matches(versionRegex);
}
}
2 changes: 2 additions & 0 deletions tink_version.bzl
@@ -0,0 +1,2 @@
""" Version of the current release of Tink """
TINK_VERSION_LABEL = "1.2.1-SNAPSHOT"

0 comments on commit 30f9a0f

Please sign in to comment.