Skip to content

Commit

Permalink
Public identifier (#38)
Browse files Browse the repository at this point in the history
* implement base58

* implement identifier

* πŸ”„ "implement identifier
"
Update anysphere/asphr commit SHA
πŸ”— anysphere/asphr@15117f2
  • Loading branch information
arvid220u authored Jun 25, 2022
1 parent c09e70c commit 67a91f0
Show file tree
Hide file tree
Showing 21 changed files with 9,755 additions and 33 deletions.
2 changes: 1 addition & 1 deletion WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")

git_repository(
name = "asphr",
commit = "6dbadec9e3796489496ea6406cfd07cd012bb9ba", # autoupdate anysphere/asphr
commit = "15117f27873a17019c0a71273d41397c93887e19", # autoupdate anysphere/asphr
init_submodules = True,
remote = "https://github.com/anysphere/asphr.git",
)
Expand Down
31 changes: 1 addition & 30 deletions daemon/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -55,24 +55,6 @@ rust_static_library(
],
)

cc_library(
name = "crypto_lib",
srcs = ["crypto/crypto.cc"],
hdrs = [
"constants.hpp",
"crypto/crypto.hpp",
],
linkstatic = True,
deps = [
"@asphr//asphr:asphr_lib",
"@asphr//schema:daemon_cc_grpc",
"@asphr//schema:message_proto_cc",
"@asphr//schema:server_cc_grpc",
"@asphr//third_party/libsodium",
"@com_github_grpc_grpc//:grpc++",
],
)

cc_library(
name = "core_lib",
srcs = ["global.cc"],
Expand All @@ -82,10 +64,10 @@ cc_library(
deps = [
":cpp_db_lib",
":cpp_include",
":crypto_lib",
":db_bridge",
":db_lib",
"//client_lib",
"//daemon/crypto:crypto_lib",
"@asphr//asphr:asphr_lib",
],
)
Expand Down Expand Up @@ -160,17 +142,6 @@ cc_library(
],
)

cc_test(
name = "crypto_test",
srcs = [
"crypto/crypto_test.cc",
],
deps = [
":crypto_lib",
"@com_google_googletest//:gtest_main",
],
)

rust_test(
name = "db_test",
crate = ":db_lib",
Expand Down
29 changes: 29 additions & 0 deletions daemon/crypto/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
cc_library(
name = "crypto_lib",
srcs = ["crypto.cc"],
hdrs = [
"constants.hpp",
"crypto.hpp",
],
linkstatic = True,
visibility = ["//daemon:__subpackages__"],
deps = [
"@asphr//asphr:asphr_lib",
"@asphr//schema:daemon_cc_grpc",
"@asphr//schema:message_proto_cc",
"@asphr//schema:server_cc_grpc",
"@asphr//third_party/libsodium",
"@com_github_grpc_grpc//:grpc++",
],
)

cc_test(
name = "crypto_test",
srcs = [
"crypto_test.cc",
],
deps = [
":crypto_lib",
"@com_google_googletest//:gtest_main",
],
)
File renamed without changes.
8 changes: 8 additions & 0 deletions daemon/crypto/crypto.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ auto generate_keypair() -> std::pair<string, string> {
string(reinterpret_cast<char*>(secret_key), crypto_kx_SECRETKEYBYTES)};
}

auto generic_hash(string_view data) -> std::string {
unsigned char hash[crypto_generichash_BYTES];
crypto_generichash(hash, sizeof hash,
reinterpret_cast<const unsigned char*>(data.data()),
data.size(), nullptr, 0);
return string(reinterpret_cast<char*>(hash), sizeof hash);
}

auto generate_friend_key(const string& my_public_key, int index) -> string {
string public_key_b64;
public_key_b64.resize(sodium_base64_ENCODED_LEN(
Expand Down
5 changes: 4 additions & 1 deletion daemon/crypto/crypto.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include <stdexcept>
#include <string>

#include "daemon/constants.hpp"
#include "constants.hpp"
#include "schema/message.pb.h"

/* Crypto implements an IND-CCA2 secure scheme.
Expand All @@ -27,6 +27,9 @@ inline auto init() -> void {
throw std::runtime_error("sodium_init failed");
}
}

auto generic_hash(string_view data) -> std::string;

// Generates a new keypair in the format <public_key, private_key>.
auto generate_keypair() -> std::pair<string, string>;

Expand Down
2 changes: 1 addition & 1 deletion daemon/global.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include "constants.hpp"
#include "crypto/constants.hpp"
#include "crypto/crypto.hpp"
#include "db/db.hpp"

Expand Down
68 changes: 68 additions & 0 deletions daemon/identifier/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
cc_library(
name = "base58",
srcs = ["base58.cc"],
hdrs = ["base58.hpp"],
deps = [
"@asphr//asphr:asphr_lib",
],
)

cc_test(
name = "base58_test",
srcs = ["base58_test.cc"],
deps = [
":base58",
"@com_google_googletest//:gtest_main",
],
)

cc_library(
name = "identifier",
srcs = ["identifier.cc"],
hdrs = [
"identifier.hpp",
"wordlist.hpp",
],
deps = [
":base58",
"//daemon/crypto:crypto_lib",
"@asphr//asphr:asphr_lib",
"@asphr//schema:identifier_proto_cc",
],
)

cc_library(
name = "identifier_helpers_private_do_not_depend_on_except_in_this_test",
srcs = ["identifier.cc"],
hdrs = [
"identifier.hpp",
"identifier_helpers_private.hpp",
"wordlist.hpp",
],
deps = [
":base58",
"//daemon/crypto:crypto_lib",
"@asphr//asphr:asphr_lib",
"@asphr//schema:identifier_proto_cc",
],
)

cc_test(
name = "identifier_test",
srcs = [
"identifier_test.cc",
],
deps = [
":identifier",
":identifier_helpers_private_do_not_depend_on_except_in_this_test",
"@com_google_googletest//:gtest_main",
],
)

cc_binary(
name = "identifier_manual_test",
srcs = ["identifier_manual_test.cc"],
deps = [
":identifier",
],
)
Loading

0 comments on commit 67a91f0

Please sign in to comment.