init ems server code
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -11,8 +11,7 @@
|
||||
.idea/
|
||||
|
||||
# Run temp file and dir
|
||||
reference
|
||||
omc/tools
|
||||
|
||||
|
||||
# Built Visual Studio Code Extensions
|
||||
*.o
|
||||
|
||||
@@ -1,352 +0,0 @@
|
||||
|
||||
##----------------------------------------------------------##
|
||||
## ##
|
||||
## Universal Makefile Rules ##
|
||||
## ##
|
||||
## Created : Wei Liu 07/03/07 ##
|
||||
## Revision: [Last]Wei Liu 07/07/07 ##
|
||||
## ##
|
||||
##----------------------------------------------------------##
|
||||
|
||||
|
||||
UMAKE_VERSION := V2.0
|
||||
|
||||
##-------------------------------------
|
||||
##
|
||||
## Work Directory : /usr/local/include
|
||||
## Default Target : all
|
||||
##
|
||||
##-------------------------------------
|
||||
default: all
|
||||
.PHONY: all clean rebuild test indent splint doc \
|
||||
dir config check bk lsbk rmbk unzip umakever usage\
|
||||
FORCE
|
||||
.SUFFIXES:
|
||||
|
||||
umakever:
|
||||
@echo "Universal Makefile (UMake) Version: $(UMAKE_VERSION)"
|
||||
|
||||
##--------------------------------------
|
||||
##
|
||||
## Makefile CFG defination check
|
||||
##
|
||||
##--------------------------------------
|
||||
|
||||
ifeq "$(MODULE)" ""
|
||||
$(error Please input the module name (MODULE = )in makefile. )
|
||||
endif
|
||||
|
||||
ifeq "$(CFG)" ""
|
||||
CFG=debug
|
||||
$(warnning No configuration specified for CFG. Defaulting to $(MODULE) - debug. )
|
||||
endif
|
||||
|
||||
ifeq "$(BUILD)" ""
|
||||
BUILD=lib
|
||||
$(warnning No configuration specified for BUILD. Defaulting to create lib$(MODULE).a. )
|
||||
endif
|
||||
|
||||
ifeq "$(SRC_PATH)" ""
|
||||
SRC_PATH=.
|
||||
$(warnning No configuration specified for SRC_PATH. Defaulting to ./. )
|
||||
endif
|
||||
|
||||
COVER_NEED ?= no
|
||||
PLT_PATH ?= ../../plat
|
||||
APP_PATH ?= ../../app
|
||||
TYPE ?= plat
|
||||
|
||||
##--------------------------------------
|
||||
##
|
||||
## Gcc Flag for debug or release
|
||||
##
|
||||
##--------------------------------------
|
||||
#CC := arm-linux-gnueabi-gcc
|
||||
CC := gcc
|
||||
GCC_CFLAGS := -Wall -MM
|
||||
#AR_LINK := arm-linux-gnueabi-ar -r
|
||||
AR_LINK := ar -r
|
||||
ARM_INCLUDE := /opt/gcc-linaro-5.4.1-2017.01-x86_64_arm-linux-gnueabi/usr/include
|
||||
RELS_FLAGS_ADD += -DNDEBUG
|
||||
RELEASE_CFLAGS += -g -I. -I$(ARM_INCLUDE) $(RELS_FLAGS_ADD)
|
||||
RELEASE_LINK_CFLAGS = -g $(RELS_FLAGS_ADD) -o
|
||||
DEBUG_CFLAGS += -g -rdynamic -finline-functions -DDEBUG -I. -I$(ARM_INCLUDE) $(DBUG_FLAGS_ADD)
|
||||
DEBUG_LINK_CFLAGS = -g -rdynamic -DDEBUG -o
|
||||
|
||||
ifeq "$(COVER_NEED)" "yes"
|
||||
DEBUG_CFLAGS += -fprofile-arcs -ftest-coverage -pg
|
||||
endif
|
||||
|
||||
GCC_CFLAGS=$(DEBUG_CFLAGS)
|
||||
GCC_LINK_CFLAGS=$(DEBUG_LINK_CFLAGS)
|
||||
|
||||
##--------------------------------------
|
||||
##
|
||||
## Project setting
|
||||
##
|
||||
##--------------------------------------
|
||||
OBJDIR:=./obj
|
||||
LIBDIR:=./lib
|
||||
UTDIR :=./ut
|
||||
DOCDIR:=./doc
|
||||
DIRBUILD=$(OBJDIR)
|
||||
|
||||
ifeq "$(BUILD)" "lib"
|
||||
BINDIR:=./bin
|
||||
OUTFILE=$(LIBDIR)/lib$(MODULE).a
|
||||
DIRNEED=$(UTDIR) $(DOCDIR)
|
||||
DIRBUILD+=$(LIBDIR)
|
||||
else
|
||||
BINDIR:=.
|
||||
OUTFILE=$(BINDIR)/$(MODULE)
|
||||
DIRNEED=
|
||||
DIRBUILD+=$(BINDIR)
|
||||
endif
|
||||
|
||||
##--------------------------------------
|
||||
##
|
||||
## source , object and dependencies files
|
||||
##
|
||||
##--------------------------------------
|
||||
|
||||
SRC_SUBDIR := $(shell find $(SRC_PATH) -type d)
|
||||
|
||||
vpath %.c $(SRC_SUBDIR)
|
||||
vpath %.o $(OBJDIR)
|
||||
vpath %.d $(OBJDIR)
|
||||
|
||||
SRC_FULL_PATH = $(foreach dir,$(SRC_SUBDIR),$(wildcard $(dir)/*.c))
|
||||
SRC_FILES = $(foreach file, $(notdir $(SRC_FULL_PATH)) ,$(OBJDIR)/$(file))
|
||||
COMMON_OBJ = $(SRC_FILES:%.c=%.o)
|
||||
|
||||
TEST_OBJ_PATH ?= ../../obj
|
||||
|
||||
TEST_OBJ = $(foreach dir,$(TEST_OBJ_PATH),$(wildcard $(dir)/*.o))
|
||||
|
||||
OBJ=$(COMMON_OBJ) $(OBJ_ADD)
|
||||
ALL_OBJ := $(OBJ) $(TEST_OBJ)
|
||||
|
||||
##--------------------------------------
|
||||
##
|
||||
## Lib setting
|
||||
##
|
||||
##--------------------------------------
|
||||
|
||||
ifeq "$(COVER_NEED)" "yes"
|
||||
LIBCOVER=-lgcov
|
||||
endif
|
||||
|
||||
MODULE_PLT_LIB=$(foreach lib,$(PLT_LIB), -L$(PLT_PATH)/$(lib)/lib/ -l$(lib) )
|
||||
MODULE_PLT_LIB+=-lm
|
||||
|
||||
|
||||
MODULE_APP_LIB=$(foreach lib,$(APP_LIB),-L$(APP_PATH)/$(lib)/lib -l$(lib))
|
||||
|
||||
ifneq (,$(findstring hlr,$(PLT_LIB)))
|
||||
MODULE_APP_LIB=
|
||||
##-L../app/ae/src/lib -lpubfunc
|
||||
endif
|
||||
|
||||
ifneq (,$(findstring auceir,$(PLT_LIB)))
|
||||
MODULE_APP_LIB=
|
||||
##-L../app/ae/src/lib -lpubfunc -L../usr/lib -la3a8 -ldl -lpopt
|
||||
endif
|
||||
|
||||
##--------------------------------------
|
||||
##
|
||||
## Rules
|
||||
##
|
||||
##--------------------------------------
|
||||
CCFLAG_SWITCH ?= off
|
||||
CC_COMPILE =$(CC) $(GCC_CFLAGS) -c $< -o $@
|
||||
CC_PRG_LINK=$(CC) $(GCC_LINK_CFLAGS) $(OUTFILE) $(ALL_OBJ) $(LIBCOVER) $(MODULE_APP_LIB) $(MODULE_PLT_LIB) $(LIB_ADD)
|
||||
CC_LIB_LINK=$(AR_LINK) $(OUTFILE) $(ALL_OBJ)
|
||||
|
||||
COMPILE=$(CC_COMPILE)
|
||||
PRG_LINK=$(CC_PRG_LINK)
|
||||
LIB_LINK=$(CC_LIB_LINK)
|
||||
|
||||
ifeq "$(BUILD)" "exef"
|
||||
LINK=$(PRG_LINK)
|
||||
else
|
||||
LINK=$(LIB_LINK)
|
||||
endif
|
||||
|
||||
# Build rules
|
||||
|
||||
all: preproc start dir $(ALL_OBJ) #prtdebug
|
||||
@echo Linking :$(OUTFILE)
|
||||
ifeq "$(CCFLAG_SWITCH)" "off"
|
||||
@$(LINK)
|
||||
else
|
||||
$(LINK)
|
||||
endif
|
||||
@$(POSTPROC_CMD)
|
||||
@echo -e "\n================================================================================\n"
|
||||
|
||||
sinclude $(DEPENDS)
|
||||
|
||||
release : CC_COMPILE =$(CC) $(RELEASE_CFLAGS) -c $< -o $@
|
||||
release : CC_PRG_LINK=$(CC) $(RELEASE_LINK_CFLAGS) $(OUTFILE) $(ALL_OBJ) $(MODULE_APP_LIB) $(MODULE_PLT_LIB) $(LIB_ADD)
|
||||
release : all
|
||||
|
||||
##--------------------------------------
|
||||
##
|
||||
## Make command to use for dependencies
|
||||
##
|
||||
##--------------------------------------
|
||||
|
||||
MAKE :=make
|
||||
RM :=rm
|
||||
MKDIR :=mkdir
|
||||
|
||||
preproc:
|
||||
@$(PREPROC_CMD)
|
||||
|
||||
start:
|
||||
@echo -e "\n================================================================================\n"
|
||||
@echo "[Building Project]: $(notdir $(MODULE))"
|
||||
ifeq "$(CCFLAG_SWITCH)" "off"
|
||||
@echo "Show Gcc Flags switch = OFF"
|
||||
endif
|
||||
|
||||
prtdebug:
|
||||
@echo "$(MODULE)-$(BUILD)[$(CFG)] build source file:" "$(SRC_FULL_PATH)"
|
||||
@echo SRC_SUBDIR: $(SRC_SUBDIR)
|
||||
@echo SRC_FULL_PATH : $(SRC_FULL_PATH)
|
||||
@echo SRC_FILES : $(SRC_FILES)
|
||||
@echo ALL_OBJ : $(ALL_OBJ)
|
||||
@echo LIB:$(MODULE_PLT_LIB)
|
||||
@echo PLT_LIB: $(PLT_LIB)
|
||||
@echo CCFLAG_SWITCH :$(CCFLAG_SWITCH)
|
||||
|
||||
config: dir
|
||||
|
||||
dir:
|
||||
@$(foreach dir,$(DIRNEED),$(MKDIR) -p $(DIRNEED) --mode=0777; )
|
||||
@$(foreach dir,$(DIRBUILD),$(MKDIR) -p $(dir) --mode=0777; )
|
||||
|
||||
##--------------------------------------
|
||||
##
|
||||
## Make Rebuild and clean
|
||||
##
|
||||
##--------------------------------------
|
||||
|
||||
ifneq "$(PROJ)" ""
|
||||
FRIEND_PROJ := $(shell )
|
||||
endif
|
||||
|
||||
jumprebuild:
|
||||
ifneq "$(PROJ)" ""
|
||||
@cd $(FRIEND_PROJ); mak rebuild ; cd -
|
||||
endif
|
||||
|
||||
# Rebuild this project
|
||||
rebuild: jumprebuild cleanall all
|
||||
|
||||
# Clean this project and all dependencies
|
||||
cleanall: clean
|
||||
|
||||
# Clean this project
|
||||
clean:
|
||||
@echo -e "||--------------------------------------------------------------- "
|
||||
@echo -e "|| Umake clean gcc , lcov, doxygen generated and temporary files. "
|
||||
@echo -e "||--------------------------------------------------------------- "
|
||||
@$(RM) -rf $(OBJDIR) $(OUTFILE) $(COVER_REPORT_PATH) ./doc/doxygen.conf ./doc/html ./doc/latex ./doc/rtf $(foreach dir,$(SRC_SUBDIR),$(dir)/*~)
|
||||
|
||||
|
||||
##--------------------------------------
|
||||
##
|
||||
## indent Makefile.indent
|
||||
##
|
||||
##--------------------------------------
|
||||
include Makefile.indent
|
||||
|
||||
indent:
|
||||
@chmod 777 $(SRC_FULL_PATH)
|
||||
@echo ===================================Indent START=================================
|
||||
@echo
|
||||
@echo "[Indent source file ]: $(SRC_FULL_PATH)"
|
||||
$(call MAKE_INDENT , $(SRC_FULL_PATH))
|
||||
|
||||
##--------------------------------------
|
||||
##
|
||||
## splint makefile.splint
|
||||
##
|
||||
##--------------------------------------
|
||||
include Makefile.splint
|
||||
|
||||
SPLINT_FLAG_SWITCH ?= off
|
||||
|
||||
splint:
|
||||
@chmod 777 $(SRC_FULL_PATH)
|
||||
@echo =================================Splint START==================================
|
||||
@echo
|
||||
ifeq "$(SPLINT_FLAG_SWITCH)" "on"
|
||||
@echo "[Splint flags ]: $(SPLINT_FLAGS)"
|
||||
endif
|
||||
@echo "[Lint Clean Project]: $(notdir $(MODULE))"
|
||||
$(call MAKE_SPLINT, $(SRC_FULL_PATH))
|
||||
|
||||
##--------------------------------------
|
||||
##
|
||||
## doc Makefile.doxygen
|
||||
##
|
||||
##--------------------------------------
|
||||
include Makefile.doxygen
|
||||
|
||||
doc:
|
||||
@chmod 777 $(SRC_FULL_PATH)
|
||||
@echo ==================================Doxygen START=================================
|
||||
@echo
|
||||
$(call MAKE_DOC, $(SRC_FULL_PATH))
|
||||
|
||||
|
||||
##--------------------------------------
|
||||
##
|
||||
## backup Makefile.backup
|
||||
##
|
||||
##--------------------------------------
|
||||
include Makefile.backup
|
||||
|
||||
##--------------------------------------
|
||||
##
|
||||
## cov Makefile.cov
|
||||
##
|
||||
##--------------------------------------
|
||||
include Makefile.cov
|
||||
|
||||
##--------------------------------------
|
||||
##
|
||||
## usage Makefile.usage
|
||||
##
|
||||
##--------------------------------------
|
||||
include Makefile.usage
|
||||
|
||||
##--------------------------------------
|
||||
##
|
||||
## Make dependencies
|
||||
##
|
||||
##--------------------------------------
|
||||
|
||||
$(OBJDIR)/%.d:%.c
|
||||
@$(CC) $< -MM -MD -o $@
|
||||
|
||||
$(OBJDIR)/%.o:%.c
|
||||
|
||||
ifeq "$(CCFLAG_SWITCH)" "off"
|
||||
@echo -e "building: $(notdir $@) \t\t\t\t please wait ..."
|
||||
@$(COMPILE)
|
||||
else
|
||||
$(COMPILE)
|
||||
endif
|
||||
|
||||
DEPENDS=$(COMMON_OBJ:.o=.d)
|
||||
|
||||
##--------------------------------------
|
||||
##
|
||||
## Make force
|
||||
##
|
||||
##--------------------------------------
|
||||
FORCE:
|
||||
|
||||
@@ -1,343 +0,0 @@
|
||||
// Copyright 2005, Google Inc.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
//
|
||||
// The Google C++ Testing and Mocking Framework (Google Test)
|
||||
//
|
||||
// This header file defines the public API for death tests. It is
|
||||
// #included by gtest.h so a user doesn't need to include this
|
||||
// directly.
|
||||
// GOOGLETEST_CM0001 DO NOT DELETE
|
||||
|
||||
#ifndef GTEST_INCLUDE_GTEST_GTEST_DEATH_TEST_H_
|
||||
#define GTEST_INCLUDE_GTEST_GTEST_DEATH_TEST_H_
|
||||
|
||||
#include "gtest/internal/gtest-death-test-internal.h"
|
||||
|
||||
namespace testing {
|
||||
|
||||
// This flag controls the style of death tests. Valid values are "threadsafe",
|
||||
// meaning that the death test child process will re-execute the test binary
|
||||
// from the start, running only a single death test, or "fast",
|
||||
// meaning that the child process will execute the test logic immediately
|
||||
// after forking.
|
||||
GTEST_DECLARE_string_(death_test_style);
|
||||
|
||||
#if GTEST_HAS_DEATH_TEST
|
||||
|
||||
namespace internal {
|
||||
|
||||
// Returns a Boolean value indicating whether the caller is currently
|
||||
// executing in the context of the death test child process. Tools such as
|
||||
// Valgrind heap checkers may need this to modify their behavior in death
|
||||
// tests. IMPORTANT: This is an internal utility. Using it may break the
|
||||
// implementation of death tests. User code MUST NOT use it.
|
||||
GTEST_API_ bool InDeathTestChild();
|
||||
|
||||
} // namespace internal
|
||||
|
||||
// The following macros are useful for writing death tests.
|
||||
|
||||
// Here's what happens when an ASSERT_DEATH* or EXPECT_DEATH* is
|
||||
// executed:
|
||||
//
|
||||
// 1. It generates a warning if there is more than one active
|
||||
// thread. This is because it's safe to fork() or clone() only
|
||||
// when there is a single thread.
|
||||
//
|
||||
// 2. The parent process clone()s a sub-process and runs the death
|
||||
// test in it; the sub-process exits with code 0 at the end of the
|
||||
// death test, if it hasn't exited already.
|
||||
//
|
||||
// 3. The parent process waits for the sub-process to terminate.
|
||||
//
|
||||
// 4. The parent process checks the exit code and error message of
|
||||
// the sub-process.
|
||||
//
|
||||
// Examples:
|
||||
//
|
||||
// ASSERT_DEATH(server.SendMessage(56, "Hello"), "Invalid port number");
|
||||
// for (int i = 0; i < 5; i++) {
|
||||
// EXPECT_DEATH(server.ProcessRequest(i),
|
||||
// "Invalid request .* in ProcessRequest()")
|
||||
// << "Failed to die on request " << i;
|
||||
// }
|
||||
//
|
||||
// ASSERT_EXIT(server.ExitNow(), ::testing::ExitedWithCode(0), "Exiting");
|
||||
//
|
||||
// bool KilledBySIGHUP(int exit_code) {
|
||||
// return WIFSIGNALED(exit_code) && WTERMSIG(exit_code) == SIGHUP;
|
||||
// }
|
||||
//
|
||||
// ASSERT_EXIT(client.HangUpServer(), KilledBySIGHUP, "Hanging up!");
|
||||
//
|
||||
// On the regular expressions used in death tests:
|
||||
//
|
||||
// GOOGLETEST_CM0005 DO NOT DELETE
|
||||
// On POSIX-compliant systems (*nix), we use the <regex.h> library,
|
||||
// which uses the POSIX extended regex syntax.
|
||||
//
|
||||
// On other platforms (e.g. Windows or Mac), we only support a simple regex
|
||||
// syntax implemented as part of Google Test. This limited
|
||||
// implementation should be enough most of the time when writing
|
||||
// death tests; though it lacks many features you can find in PCRE
|
||||
// or POSIX extended regex syntax. For example, we don't support
|
||||
// union ("x|y"), grouping ("(xy)"), brackets ("[xy]"), and
|
||||
// repetition count ("x{5,7}"), among others.
|
||||
//
|
||||
// Below is the syntax that we do support. We chose it to be a
|
||||
// subset of both PCRE and POSIX extended regex, so it's easy to
|
||||
// learn wherever you come from. In the following: 'A' denotes a
|
||||
// literal character, period (.), or a single \\ escape sequence;
|
||||
// 'x' and 'y' denote regular expressions; 'm' and 'n' are for
|
||||
// natural numbers.
|
||||
//
|
||||
// c matches any literal character c
|
||||
// \\d matches any decimal digit
|
||||
// \\D matches any character that's not a decimal digit
|
||||
// \\f matches \f
|
||||
// \\n matches \n
|
||||
// \\r matches \r
|
||||
// \\s matches any ASCII whitespace, including \n
|
||||
// \\S matches any character that's not a whitespace
|
||||
// \\t matches \t
|
||||
// \\v matches \v
|
||||
// \\w matches any letter, _, or decimal digit
|
||||
// \\W matches any character that \\w doesn't match
|
||||
// \\c matches any literal character c, which must be a punctuation
|
||||
// . matches any single character except \n
|
||||
// A? matches 0 or 1 occurrences of A
|
||||
// A* matches 0 or many occurrences of A
|
||||
// A+ matches 1 or many occurrences of A
|
||||
// ^ matches the beginning of a string (not that of each line)
|
||||
// $ matches the end of a string (not that of each line)
|
||||
// xy matches x followed by y
|
||||
//
|
||||
// If you accidentally use PCRE or POSIX extended regex features
|
||||
// not implemented by us, you will get a run-time failure. In that
|
||||
// case, please try to rewrite your regular expression within the
|
||||
// above syntax.
|
||||
//
|
||||
// This implementation is *not* meant to be as highly tuned or robust
|
||||
// as a compiled regex library, but should perform well enough for a
|
||||
// death test, which already incurs significant overhead by launching
|
||||
// a child process.
|
||||
//
|
||||
// Known caveats:
|
||||
//
|
||||
// A "threadsafe" style death test obtains the path to the test
|
||||
// program from argv[0] and re-executes it in the sub-process. For
|
||||
// simplicity, the current implementation doesn't search the PATH
|
||||
// when launching the sub-process. This means that the user must
|
||||
// invoke the test program via a path that contains at least one
|
||||
// path separator (e.g. path/to/foo_test and
|
||||
// /absolute/path/to/bar_test are fine, but foo_test is not). This
|
||||
// is rarely a problem as people usually don't put the test binary
|
||||
// directory in PATH.
|
||||
//
|
||||
|
||||
// Asserts that a given statement causes the program to exit, with an
|
||||
// integer exit status that satisfies predicate, and emitting error output
|
||||
// that matches regex.
|
||||
# define ASSERT_EXIT(statement, predicate, regex) \
|
||||
GTEST_DEATH_TEST_(statement, predicate, regex, GTEST_FATAL_FAILURE_)
|
||||
|
||||
// Like ASSERT_EXIT, but continues on to successive tests in the
|
||||
// test suite, if any:
|
||||
# define EXPECT_EXIT(statement, predicate, regex) \
|
||||
GTEST_DEATH_TEST_(statement, predicate, regex, GTEST_NONFATAL_FAILURE_)
|
||||
|
||||
// Asserts that a given statement causes the program to exit, either by
|
||||
// explicitly exiting with a nonzero exit code or being killed by a
|
||||
// signal, and emitting error output that matches regex.
|
||||
# define ASSERT_DEATH(statement, regex) \
|
||||
ASSERT_EXIT(statement, ::testing::internal::ExitedUnsuccessfully, regex)
|
||||
|
||||
// Like ASSERT_DEATH, but continues on to successive tests in the
|
||||
// test suite, if any:
|
||||
# define EXPECT_DEATH(statement, regex) \
|
||||
EXPECT_EXIT(statement, ::testing::internal::ExitedUnsuccessfully, regex)
|
||||
|
||||
// Two predicate classes that can be used in {ASSERT,EXPECT}_EXIT*:
|
||||
|
||||
// Tests that an exit code describes a normal exit with a given exit code.
|
||||
class GTEST_API_ ExitedWithCode {
|
||||
public:
|
||||
explicit ExitedWithCode(int exit_code);
|
||||
bool operator()(int exit_status) const;
|
||||
private:
|
||||
// No implementation - assignment is unsupported.
|
||||
void operator=(const ExitedWithCode& other);
|
||||
|
||||
const int exit_code_;
|
||||
};
|
||||
|
||||
# if !GTEST_OS_WINDOWS && !GTEST_OS_FUCHSIA
|
||||
// Tests that an exit code describes an exit due to termination by a
|
||||
// given signal.
|
||||
// GOOGLETEST_CM0006 DO NOT DELETE
|
||||
class GTEST_API_ KilledBySignal {
|
||||
public:
|
||||
explicit KilledBySignal(int signum);
|
||||
bool operator()(int exit_status) const;
|
||||
private:
|
||||
const int signum_;
|
||||
};
|
||||
# endif // !GTEST_OS_WINDOWS
|
||||
|
||||
// EXPECT_DEBUG_DEATH asserts that the given statements die in debug mode.
|
||||
// The death testing framework causes this to have interesting semantics,
|
||||
// since the sideeffects of the call are only visible in opt mode, and not
|
||||
// in debug mode.
|
||||
//
|
||||
// In practice, this can be used to test functions that utilize the
|
||||
// LOG(DFATAL) macro using the following style:
|
||||
//
|
||||
// int DieInDebugOr12(int* sideeffect) {
|
||||
// if (sideeffect) {
|
||||
// *sideeffect = 12;
|
||||
// }
|
||||
// LOG(DFATAL) << "death";
|
||||
// return 12;
|
||||
// }
|
||||
//
|
||||
// TEST(TestSuite, TestDieOr12WorksInDgbAndOpt) {
|
||||
// int sideeffect = 0;
|
||||
// // Only asserts in dbg.
|
||||
// EXPECT_DEBUG_DEATH(DieInDebugOr12(&sideeffect), "death");
|
||||
//
|
||||
// #ifdef NDEBUG
|
||||
// // opt-mode has sideeffect visible.
|
||||
// EXPECT_EQ(12, sideeffect);
|
||||
// #else
|
||||
// // dbg-mode no visible sideeffect.
|
||||
// EXPECT_EQ(0, sideeffect);
|
||||
// #endif
|
||||
// }
|
||||
//
|
||||
// This will assert that DieInDebugReturn12InOpt() crashes in debug
|
||||
// mode, usually due to a DCHECK or LOG(DFATAL), but returns the
|
||||
// appropriate fallback value (12 in this case) in opt mode. If you
|
||||
// need to test that a function has appropriate side-effects in opt
|
||||
// mode, include assertions against the side-effects. A general
|
||||
// pattern for this is:
|
||||
//
|
||||
// EXPECT_DEBUG_DEATH({
|
||||
// // Side-effects here will have an effect after this statement in
|
||||
// // opt mode, but none in debug mode.
|
||||
// EXPECT_EQ(12, DieInDebugOr12(&sideeffect));
|
||||
// }, "death");
|
||||
//
|
||||
# ifdef NDEBUG
|
||||
|
||||
# define EXPECT_DEBUG_DEATH(statement, regex) \
|
||||
GTEST_EXECUTE_STATEMENT_(statement, regex)
|
||||
|
||||
# define ASSERT_DEBUG_DEATH(statement, regex) \
|
||||
GTEST_EXECUTE_STATEMENT_(statement, regex)
|
||||
|
||||
# else
|
||||
|
||||
# define EXPECT_DEBUG_DEATH(statement, regex) \
|
||||
EXPECT_DEATH(statement, regex)
|
||||
|
||||
# define ASSERT_DEBUG_DEATH(statement, regex) \
|
||||
ASSERT_DEATH(statement, regex)
|
||||
|
||||
# endif // NDEBUG for EXPECT_DEBUG_DEATH
|
||||
#endif // GTEST_HAS_DEATH_TEST
|
||||
|
||||
// This macro is used for implementing macros such as
|
||||
// EXPECT_DEATH_IF_SUPPORTED and ASSERT_DEATH_IF_SUPPORTED on systems where
|
||||
// death tests are not supported. Those macros must compile on such systems
|
||||
// if and only if EXPECT_DEATH and ASSERT_DEATH compile with the same parameters
|
||||
// on systems that support death tests. This allows one to write such a macro on
|
||||
// a system that does not support death tests and be sure that it will compile
|
||||
// on a death-test supporting system. It is exposed publicly so that systems
|
||||
// that have death-tests with stricter requirements than GTEST_HAS_DEATH_TEST
|
||||
// can write their own equivalent of EXPECT_DEATH_IF_SUPPORTED and
|
||||
// ASSERT_DEATH_IF_SUPPORTED.
|
||||
//
|
||||
// Parameters:
|
||||
// statement - A statement that a macro such as EXPECT_DEATH would test
|
||||
// for program termination. This macro has to make sure this
|
||||
// statement is compiled but not executed, to ensure that
|
||||
// EXPECT_DEATH_IF_SUPPORTED compiles with a certain
|
||||
// parameter if and only if EXPECT_DEATH compiles with it.
|
||||
// regex - A regex that a macro such as EXPECT_DEATH would use to test
|
||||
// the output of statement. This parameter has to be
|
||||
// compiled but not evaluated by this macro, to ensure that
|
||||
// this macro only accepts expressions that a macro such as
|
||||
// EXPECT_DEATH would accept.
|
||||
// terminator - Must be an empty statement for EXPECT_DEATH_IF_SUPPORTED
|
||||
// and a return statement for ASSERT_DEATH_IF_SUPPORTED.
|
||||
// This ensures that ASSERT_DEATH_IF_SUPPORTED will not
|
||||
// compile inside functions where ASSERT_DEATH doesn't
|
||||
// compile.
|
||||
//
|
||||
// The branch that has an always false condition is used to ensure that
|
||||
// statement and regex are compiled (and thus syntactically correct) but
|
||||
// never executed. The unreachable code macro protects the terminator
|
||||
// statement from generating an 'unreachable code' warning in case
|
||||
// statement unconditionally returns or throws. The Message constructor at
|
||||
// the end allows the syntax of streaming additional messages into the
|
||||
// macro, for compilational compatibility with EXPECT_DEATH/ASSERT_DEATH.
|
||||
# define GTEST_UNSUPPORTED_DEATH_TEST(statement, regex, terminator) \
|
||||
GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
|
||||
if (::testing::internal::AlwaysTrue()) { \
|
||||
GTEST_LOG_(WARNING) \
|
||||
<< "Death tests are not supported on this platform.\n" \
|
||||
<< "Statement '" #statement "' cannot be verified."; \
|
||||
} else if (::testing::internal::AlwaysFalse()) { \
|
||||
::testing::internal::RE::PartialMatch(".*", (regex)); \
|
||||
GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
|
||||
terminator; \
|
||||
} else \
|
||||
::testing::Message()
|
||||
|
||||
// EXPECT_DEATH_IF_SUPPORTED(statement, regex) and
|
||||
// ASSERT_DEATH_IF_SUPPORTED(statement, regex) expand to real death tests if
|
||||
// death tests are supported; otherwise they just issue a warning. This is
|
||||
// useful when you are combining death test assertions with normal test
|
||||
// assertions in one test.
|
||||
#if GTEST_HAS_DEATH_TEST
|
||||
# define EXPECT_DEATH_IF_SUPPORTED(statement, regex) \
|
||||
EXPECT_DEATH(statement, regex)
|
||||
# define ASSERT_DEATH_IF_SUPPORTED(statement, regex) \
|
||||
ASSERT_DEATH(statement, regex)
|
||||
#else
|
||||
# define EXPECT_DEATH_IF_SUPPORTED(statement, regex) \
|
||||
GTEST_UNSUPPORTED_DEATH_TEST(statement, regex, )
|
||||
# define ASSERT_DEATH_IF_SUPPORTED(statement, regex) \
|
||||
GTEST_UNSUPPORTED_DEATH_TEST(statement, regex, return)
|
||||
#endif
|
||||
|
||||
} // namespace testing
|
||||
|
||||
#endif // GTEST_INCLUDE_GTEST_GTEST_DEATH_TEST_H_
|
||||
@@ -1,750 +0,0 @@
|
||||
// Copyright 2007, Google Inc.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// The Google C++ Testing and Mocking Framework (Google Test)
|
||||
//
|
||||
// This file implements just enough of the matcher interface to allow
|
||||
// EXPECT_DEATH and friends to accept a matcher argument.
|
||||
|
||||
// IWYU pragma: private, include "testing/base/public/gunit.h"
|
||||
// IWYU pragma: friend third_party/googletest/googlemock/.*
|
||||
// IWYU pragma: friend third_party/googletest/googletest/.*
|
||||
|
||||
#ifndef GTEST_INCLUDE_GTEST_GTEST_MATCHERS_H_
|
||||
#define GTEST_INCLUDE_GTEST_GTEST_MATCHERS_H_
|
||||
|
||||
#include <memory>
|
||||
#include <ostream>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
|
||||
#include "gtest/gtest-printers.h"
|
||||
#include "gtest/internal/gtest-internal.h"
|
||||
#include "gtest/internal/gtest-port.h"
|
||||
|
||||
// MSVC warning C5046 is new as of VS2017 version 15.8.
|
||||
#if defined(_MSC_VER) && _MSC_VER >= 1915
|
||||
#define GTEST_MAYBE_5046_ 5046
|
||||
#else
|
||||
#define GTEST_MAYBE_5046_
|
||||
#endif
|
||||
|
||||
GTEST_DISABLE_MSC_WARNINGS_PUSH_(
|
||||
4251 GTEST_MAYBE_5046_ /* class A needs to have dll-interface to be used by
|
||||
clients of class B */
|
||||
/* Symbol involving type with internal linkage not defined */)
|
||||
|
||||
namespace testing {
|
||||
|
||||
// To implement a matcher Foo for type T, define:
|
||||
// 1. a class FooMatcherImpl that implements the
|
||||
// MatcherInterface<T> interface, and
|
||||
// 2. a factory function that creates a Matcher<T> object from a
|
||||
// FooMatcherImpl*.
|
||||
//
|
||||
// The two-level delegation design makes it possible to allow a user
|
||||
// to write "v" instead of "Eq(v)" where a Matcher is expected, which
|
||||
// is impossible if we pass matchers by pointers. It also eases
|
||||
// ownership management as Matcher objects can now be copied like
|
||||
// plain values.
|
||||
|
||||
// MatchResultListener is an abstract class. Its << operator can be
|
||||
// used by a matcher to explain why a value matches or doesn't match.
|
||||
//
|
||||
class MatchResultListener {
|
||||
public:
|
||||
// Creates a listener object with the given underlying ostream. The
|
||||
// listener does not own the ostream, and does not dereference it
|
||||
// in the constructor or destructor.
|
||||
explicit MatchResultListener(::std::ostream* os) : stream_(os) {}
|
||||
virtual ~MatchResultListener() = 0; // Makes this class abstract.
|
||||
|
||||
// Streams x to the underlying ostream; does nothing if the ostream
|
||||
// is NULL.
|
||||
template <typename T>
|
||||
MatchResultListener& operator<<(const T& x) {
|
||||
if (stream_ != nullptr) *stream_ << x;
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Returns the underlying ostream.
|
||||
::std::ostream* stream() { return stream_; }
|
||||
|
||||
// Returns true if and only if the listener is interested in an explanation
|
||||
// of the match result. A matcher's MatchAndExplain() method can use
|
||||
// this information to avoid generating the explanation when no one
|
||||
// intends to hear it.
|
||||
bool IsInterested() const { return stream_ != nullptr; }
|
||||
|
||||
private:
|
||||
::std::ostream* const stream_;
|
||||
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(MatchResultListener);
|
||||
};
|
||||
|
||||
inline MatchResultListener::~MatchResultListener() {
|
||||
}
|
||||
|
||||
// An instance of a subclass of this knows how to describe itself as a
|
||||
// matcher.
|
||||
class MatcherDescriberInterface {
|
||||
public:
|
||||
virtual ~MatcherDescriberInterface() {}
|
||||
|
||||
// Describes this matcher to an ostream. The function should print
|
||||
// a verb phrase that describes the property a value matching this
|
||||
// matcher should have. The subject of the verb phrase is the value
|
||||
// being matched. For example, the DescribeTo() method of the Gt(7)
|
||||
// matcher prints "is greater than 7".
|
||||
virtual void DescribeTo(::std::ostream* os) const = 0;
|
||||
|
||||
// Describes the negation of this matcher to an ostream. For
|
||||
// example, if the description of this matcher is "is greater than
|
||||
// 7", the negated description could be "is not greater than 7".
|
||||
// You are not required to override this when implementing
|
||||
// MatcherInterface, but it is highly advised so that your matcher
|
||||
// can produce good error messages.
|
||||
virtual void DescribeNegationTo(::std::ostream* os) const {
|
||||
*os << "not (";
|
||||
DescribeTo(os);
|
||||
*os << ")";
|
||||
}
|
||||
};
|
||||
|
||||
// The implementation of a matcher.
|
||||
template <typename T>
|
||||
class MatcherInterface : public MatcherDescriberInterface {
|
||||
public:
|
||||
// Returns true if and only if the matcher matches x; also explains the
|
||||
// match result to 'listener' if necessary (see the next paragraph), in
|
||||
// the form of a non-restrictive relative clause ("which ...",
|
||||
// "whose ...", etc) that describes x. For example, the
|
||||
// MatchAndExplain() method of the Pointee(...) matcher should
|
||||
// generate an explanation like "which points to ...".
|
||||
//
|
||||
// Implementations of MatchAndExplain() should add an explanation of
|
||||
// the match result *if and only if* they can provide additional
|
||||
// information that's not already present (or not obvious) in the
|
||||
// print-out of x and the matcher's description. Whether the match
|
||||
// succeeds is not a factor in deciding whether an explanation is
|
||||
// needed, as sometimes the caller needs to print a failure message
|
||||
// when the match succeeds (e.g. when the matcher is used inside
|
||||
// Not()).
|
||||
//
|
||||
// For example, a "has at least 10 elements" matcher should explain
|
||||
// what the actual element count is, regardless of the match result,
|
||||
// as it is useful information to the reader; on the other hand, an
|
||||
// "is empty" matcher probably only needs to explain what the actual
|
||||
// size is when the match fails, as it's redundant to say that the
|
||||
// size is 0 when the value is already known to be empty.
|
||||
//
|
||||
// You should override this method when defining a new matcher.
|
||||
//
|
||||
// It's the responsibility of the caller (Google Test) to guarantee
|
||||
// that 'listener' is not NULL. This helps to simplify a matcher's
|
||||
// implementation when it doesn't care about the performance, as it
|
||||
// can talk to 'listener' without checking its validity first.
|
||||
// However, in order to implement dummy listeners efficiently,
|
||||
// listener->stream() may be NULL.
|
||||
virtual bool MatchAndExplain(T x, MatchResultListener* listener) const = 0;
|
||||
|
||||
// Inherits these methods from MatcherDescriberInterface:
|
||||
// virtual void DescribeTo(::std::ostream* os) const = 0;
|
||||
// virtual void DescribeNegationTo(::std::ostream* os) const;
|
||||
};
|
||||
|
||||
namespace internal {
|
||||
|
||||
// Converts a MatcherInterface<T> to a MatcherInterface<const T&>.
|
||||
template <typename T>
|
||||
class MatcherInterfaceAdapter : public MatcherInterface<const T&> {
|
||||
public:
|
||||
explicit MatcherInterfaceAdapter(const MatcherInterface<T>* impl)
|
||||
: impl_(impl) {}
|
||||
~MatcherInterfaceAdapter() override { delete impl_; }
|
||||
|
||||
void DescribeTo(::std::ostream* os) const override { impl_->DescribeTo(os); }
|
||||
|
||||
void DescribeNegationTo(::std::ostream* os) const override {
|
||||
impl_->DescribeNegationTo(os);
|
||||
}
|
||||
|
||||
bool MatchAndExplain(const T& x,
|
||||
MatchResultListener* listener) const override {
|
||||
return impl_->MatchAndExplain(x, listener);
|
||||
}
|
||||
|
||||
private:
|
||||
const MatcherInterface<T>* const impl_;
|
||||
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(MatcherInterfaceAdapter);
|
||||
};
|
||||
|
||||
struct AnyEq {
|
||||
template <typename A, typename B>
|
||||
bool operator()(const A& a, const B& b) const { return a == b; }
|
||||
};
|
||||
struct AnyNe {
|
||||
template <typename A, typename B>
|
||||
bool operator()(const A& a, const B& b) const { return a != b; }
|
||||
};
|
||||
struct AnyLt {
|
||||
template <typename A, typename B>
|
||||
bool operator()(const A& a, const B& b) const { return a < b; }
|
||||
};
|
||||
struct AnyGt {
|
||||
template <typename A, typename B>
|
||||
bool operator()(const A& a, const B& b) const { return a > b; }
|
||||
};
|
||||
struct AnyLe {
|
||||
template <typename A, typename B>
|
||||
bool operator()(const A& a, const B& b) const { return a <= b; }
|
||||
};
|
||||
struct AnyGe {
|
||||
template <typename A, typename B>
|
||||
bool operator()(const A& a, const B& b) const { return a >= b; }
|
||||
};
|
||||
|
||||
// A match result listener that ignores the explanation.
|
||||
class DummyMatchResultListener : public MatchResultListener {
|
||||
public:
|
||||
DummyMatchResultListener() : MatchResultListener(nullptr) {}
|
||||
|
||||
private:
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(DummyMatchResultListener);
|
||||
};
|
||||
|
||||
// A match result listener that forwards the explanation to a given
|
||||
// ostream. The difference between this and MatchResultListener is
|
||||
// that the former is concrete.
|
||||
class StreamMatchResultListener : public MatchResultListener {
|
||||
public:
|
||||
explicit StreamMatchResultListener(::std::ostream* os)
|
||||
: MatchResultListener(os) {}
|
||||
|
||||
private:
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(StreamMatchResultListener);
|
||||
};
|
||||
|
||||
// An internal class for implementing Matcher<T>, which will derive
|
||||
// from it. We put functionalities common to all Matcher<T>
|
||||
// specializations here to avoid code duplication.
|
||||
template <typename T>
|
||||
class MatcherBase {
|
||||
public:
|
||||
// Returns true if and only if the matcher matches x; also explains the
|
||||
// match result to 'listener'.
|
||||
bool MatchAndExplain(const T& x, MatchResultListener* listener) const {
|
||||
return impl_->MatchAndExplain(x, listener);
|
||||
}
|
||||
|
||||
// Returns true if and only if this matcher matches x.
|
||||
bool Matches(const T& x) const {
|
||||
DummyMatchResultListener dummy;
|
||||
return MatchAndExplain(x, &dummy);
|
||||
}
|
||||
|
||||
// Describes this matcher to an ostream.
|
||||
void DescribeTo(::std::ostream* os) const { impl_->DescribeTo(os); }
|
||||
|
||||
// Describes the negation of this matcher to an ostream.
|
||||
void DescribeNegationTo(::std::ostream* os) const {
|
||||
impl_->DescribeNegationTo(os);
|
||||
}
|
||||
|
||||
// Explains why x matches, or doesn't match, the matcher.
|
||||
void ExplainMatchResultTo(const T& x, ::std::ostream* os) const {
|
||||
StreamMatchResultListener listener(os);
|
||||
MatchAndExplain(x, &listener);
|
||||
}
|
||||
|
||||
// Returns the describer for this matcher object; retains ownership
|
||||
// of the describer, which is only guaranteed to be alive when
|
||||
// this matcher object is alive.
|
||||
const MatcherDescriberInterface* GetDescriber() const {
|
||||
return impl_.get();
|
||||
}
|
||||
|
||||
protected:
|
||||
MatcherBase() {}
|
||||
|
||||
// Constructs a matcher from its implementation.
|
||||
explicit MatcherBase(const MatcherInterface<const T&>* impl) : impl_(impl) {}
|
||||
|
||||
template <typename U>
|
||||
explicit MatcherBase(
|
||||
const MatcherInterface<U>* impl,
|
||||
typename std::enable_if<!std::is_same<U, const U&>::value>::type* =
|
||||
nullptr)
|
||||
: impl_(new internal::MatcherInterfaceAdapter<U>(impl)) {}
|
||||
|
||||
MatcherBase(const MatcherBase&) = default;
|
||||
MatcherBase& operator=(const MatcherBase&) = default;
|
||||
MatcherBase(MatcherBase&&) = default;
|
||||
MatcherBase& operator=(MatcherBase&&) = default;
|
||||
|
||||
virtual ~MatcherBase() {}
|
||||
|
||||
private:
|
||||
std::shared_ptr<const MatcherInterface<const T&>> impl_;
|
||||
};
|
||||
|
||||
} // namespace internal
|
||||
|
||||
// A Matcher<T> is a copyable and IMMUTABLE (except by assignment)
|
||||
// object that can check whether a value of type T matches. The
|
||||
// implementation of Matcher<T> is just a std::shared_ptr to const
|
||||
// MatcherInterface<T>. Don't inherit from Matcher!
|
||||
template <typename T>
|
||||
class Matcher : public internal::MatcherBase<T> {
|
||||
public:
|
||||
// Constructs a null matcher. Needed for storing Matcher objects in STL
|
||||
// containers. A default-constructed matcher is not yet initialized. You
|
||||
// cannot use it until a valid value has been assigned to it.
|
||||
explicit Matcher() {} // NOLINT
|
||||
|
||||
// Constructs a matcher from its implementation.
|
||||
explicit Matcher(const MatcherInterface<const T&>* impl)
|
||||
: internal::MatcherBase<T>(impl) {}
|
||||
|
||||
template <typename U>
|
||||
explicit Matcher(
|
||||
const MatcherInterface<U>* impl,
|
||||
typename std::enable_if<!std::is_same<U, const U&>::value>::type* =
|
||||
nullptr)
|
||||
: internal::MatcherBase<T>(impl) {}
|
||||
|
||||
// Implicit constructor here allows people to write
|
||||
// EXPECT_CALL(foo, Bar(5)) instead of EXPECT_CALL(foo, Bar(Eq(5))) sometimes
|
||||
Matcher(T value); // NOLINT
|
||||
};
|
||||
|
||||
// The following two specializations allow the user to write str
|
||||
// instead of Eq(str) and "foo" instead of Eq("foo") when a std::string
|
||||
// matcher is expected.
|
||||
template <>
|
||||
class GTEST_API_ Matcher<const std::string&>
|
||||
: public internal::MatcherBase<const std::string&> {
|
||||
public:
|
||||
Matcher() {}
|
||||
|
||||
explicit Matcher(const MatcherInterface<const std::string&>* impl)
|
||||
: internal::MatcherBase<const std::string&>(impl) {}
|
||||
|
||||
// Allows the user to write str instead of Eq(str) sometimes, where
|
||||
// str is a std::string object.
|
||||
Matcher(const std::string& s); // NOLINT
|
||||
|
||||
// Allows the user to write "foo" instead of Eq("foo") sometimes.
|
||||
Matcher(const char* s); // NOLINT
|
||||
};
|
||||
|
||||
template <>
|
||||
class GTEST_API_ Matcher<std::string>
|
||||
: public internal::MatcherBase<std::string> {
|
||||
public:
|
||||
Matcher() {}
|
||||
|
||||
explicit Matcher(const MatcherInterface<const std::string&>* impl)
|
||||
: internal::MatcherBase<std::string>(impl) {}
|
||||
explicit Matcher(const MatcherInterface<std::string>* impl)
|
||||
: internal::MatcherBase<std::string>(impl) {}
|
||||
|
||||
// Allows the user to write str instead of Eq(str) sometimes, where
|
||||
// str is a string object.
|
||||
Matcher(const std::string& s); // NOLINT
|
||||
|
||||
// Allows the user to write "foo" instead of Eq("foo") sometimes.
|
||||
Matcher(const char* s); // NOLINT
|
||||
};
|
||||
|
||||
#if GTEST_HAS_ABSL
|
||||
// The following two specializations allow the user to write str
|
||||
// instead of Eq(str) and "foo" instead of Eq("foo") when a absl::string_view
|
||||
// matcher is expected.
|
||||
template <>
|
||||
class GTEST_API_ Matcher<const absl::string_view&>
|
||||
: public internal::MatcherBase<const absl::string_view&> {
|
||||
public:
|
||||
Matcher() {}
|
||||
|
||||
explicit Matcher(const MatcherInterface<const absl::string_view&>* impl)
|
||||
: internal::MatcherBase<const absl::string_view&>(impl) {}
|
||||
|
||||
// Allows the user to write str instead of Eq(str) sometimes, where
|
||||
// str is a std::string object.
|
||||
Matcher(const std::string& s); // NOLINT
|
||||
|
||||
// Allows the user to write "foo" instead of Eq("foo") sometimes.
|
||||
Matcher(const char* s); // NOLINT
|
||||
|
||||
// Allows the user to pass absl::string_views directly.
|
||||
Matcher(absl::string_view s); // NOLINT
|
||||
};
|
||||
|
||||
template <>
|
||||
class GTEST_API_ Matcher<absl::string_view>
|
||||
: public internal::MatcherBase<absl::string_view> {
|
||||
public:
|
||||
Matcher() {}
|
||||
|
||||
explicit Matcher(const MatcherInterface<const absl::string_view&>* impl)
|
||||
: internal::MatcherBase<absl::string_view>(impl) {}
|
||||
explicit Matcher(const MatcherInterface<absl::string_view>* impl)
|
||||
: internal::MatcherBase<absl::string_view>(impl) {}
|
||||
|
||||
// Allows the user to write str instead of Eq(str) sometimes, where
|
||||
// str is a std::string object.
|
||||
Matcher(const std::string& s); // NOLINT
|
||||
|
||||
// Allows the user to write "foo" instead of Eq("foo") sometimes.
|
||||
Matcher(const char* s); // NOLINT
|
||||
|
||||
// Allows the user to pass absl::string_views directly.
|
||||
Matcher(absl::string_view s); // NOLINT
|
||||
};
|
||||
#endif // GTEST_HAS_ABSL
|
||||
|
||||
// Prints a matcher in a human-readable format.
|
||||
template <typename T>
|
||||
std::ostream& operator<<(std::ostream& os, const Matcher<T>& matcher) {
|
||||
matcher.DescribeTo(&os);
|
||||
return os;
|
||||
}
|
||||
|
||||
// The PolymorphicMatcher class template makes it easy to implement a
|
||||
// polymorphic matcher (i.e. a matcher that can match values of more
|
||||
// than one type, e.g. Eq(n) and NotNull()).
|
||||
//
|
||||
// To define a polymorphic matcher, a user should provide an Impl
|
||||
// class that has a DescribeTo() method and a DescribeNegationTo()
|
||||
// method, and define a member function (or member function template)
|
||||
//
|
||||
// bool MatchAndExplain(const Value& value,
|
||||
// MatchResultListener* listener) const;
|
||||
//
|
||||
// See the definition of NotNull() for a complete example.
|
||||
template <class Impl>
|
||||
class PolymorphicMatcher {
|
||||
public:
|
||||
explicit PolymorphicMatcher(const Impl& an_impl) : impl_(an_impl) {}
|
||||
|
||||
// Returns a mutable reference to the underlying matcher
|
||||
// implementation object.
|
||||
Impl& mutable_impl() { return impl_; }
|
||||
|
||||
// Returns an immutable reference to the underlying matcher
|
||||
// implementation object.
|
||||
const Impl& impl() const { return impl_; }
|
||||
|
||||
template <typename T>
|
||||
operator Matcher<T>() const {
|
||||
return Matcher<T>(new MonomorphicImpl<const T&>(impl_));
|
||||
}
|
||||
|
||||
private:
|
||||
template <typename T>
|
||||
class MonomorphicImpl : public MatcherInterface<T> {
|
||||
public:
|
||||
explicit MonomorphicImpl(const Impl& impl) : impl_(impl) {}
|
||||
|
||||
virtual void DescribeTo(::std::ostream* os) const { impl_.DescribeTo(os); }
|
||||
|
||||
virtual void DescribeNegationTo(::std::ostream* os) const {
|
||||
impl_.DescribeNegationTo(os);
|
||||
}
|
||||
|
||||
virtual bool MatchAndExplain(T x, MatchResultListener* listener) const {
|
||||
return impl_.MatchAndExplain(x, listener);
|
||||
}
|
||||
|
||||
private:
|
||||
const Impl impl_;
|
||||
};
|
||||
|
||||
Impl impl_;
|
||||
};
|
||||
|
||||
// Creates a matcher from its implementation.
|
||||
// DEPRECATED: Especially in the generic code, prefer:
|
||||
// Matcher<T>(new MyMatcherImpl<const T&>(...));
|
||||
//
|
||||
// MakeMatcher may create a Matcher that accepts its argument by value, which
|
||||
// leads to unnecessary copies & lack of support for non-copyable types.
|
||||
template <typename T>
|
||||
inline Matcher<T> MakeMatcher(const MatcherInterface<T>* impl) {
|
||||
return Matcher<T>(impl);
|
||||
}
|
||||
|
||||
// Creates a polymorphic matcher from its implementation. This is
|
||||
// easier to use than the PolymorphicMatcher<Impl> constructor as it
|
||||
// doesn't require you to explicitly write the template argument, e.g.
|
||||
//
|
||||
// MakePolymorphicMatcher(foo);
|
||||
// vs
|
||||
// PolymorphicMatcher<TypeOfFoo>(foo);
|
||||
template <class Impl>
|
||||
inline PolymorphicMatcher<Impl> MakePolymorphicMatcher(const Impl& impl) {
|
||||
return PolymorphicMatcher<Impl>(impl);
|
||||
}
|
||||
|
||||
namespace internal {
|
||||
// Implements a matcher that compares a given value with a
|
||||
// pre-supplied value using one of the ==, <=, <, etc, operators. The
|
||||
// two values being compared don't have to have the same type.
|
||||
//
|
||||
// The matcher defined here is polymorphic (for example, Eq(5) can be
|
||||
// used to match an int, a short, a double, etc). Therefore we use
|
||||
// a template type conversion operator in the implementation.
|
||||
//
|
||||
// The following template definition assumes that the Rhs parameter is
|
||||
// a "bare" type (i.e. neither 'const T' nor 'T&').
|
||||
template <typename D, typename Rhs, typename Op>
|
||||
class ComparisonBase {
|
||||
public:
|
||||
explicit ComparisonBase(const Rhs& rhs) : rhs_(rhs) {}
|
||||
template <typename Lhs>
|
||||
operator Matcher<Lhs>() const {
|
||||
return Matcher<Lhs>(new Impl<const Lhs&>(rhs_));
|
||||
}
|
||||
|
||||
private:
|
||||
template <typename T>
|
||||
static const T& Unwrap(const T& v) { return v; }
|
||||
template <typename T>
|
||||
static const T& Unwrap(std::reference_wrapper<T> v) { return v; }
|
||||
|
||||
template <typename Lhs, typename = Rhs>
|
||||
class Impl : public MatcherInterface<Lhs> {
|
||||
public:
|
||||
explicit Impl(const Rhs& rhs) : rhs_(rhs) {}
|
||||
bool MatchAndExplain(Lhs lhs,
|
||||
MatchResultListener* /* listener */) const override {
|
||||
return Op()(lhs, Unwrap(rhs_));
|
||||
}
|
||||
void DescribeTo(::std::ostream* os) const override {
|
||||
*os << D::Desc() << " ";
|
||||
UniversalPrint(Unwrap(rhs_), os);
|
||||
}
|
||||
void DescribeNegationTo(::std::ostream* os) const override {
|
||||
*os << D::NegatedDesc() << " ";
|
||||
UniversalPrint(Unwrap(rhs_), os);
|
||||
}
|
||||
|
||||
private:
|
||||
Rhs rhs_;
|
||||
};
|
||||
Rhs rhs_;
|
||||
};
|
||||
|
||||
template <typename Rhs>
|
||||
class EqMatcher : public ComparisonBase<EqMatcher<Rhs>, Rhs, AnyEq> {
|
||||
public:
|
||||
explicit EqMatcher(const Rhs& rhs)
|
||||
: ComparisonBase<EqMatcher<Rhs>, Rhs, AnyEq>(rhs) { }
|
||||
static const char* Desc() { return "is equal to"; }
|
||||
static const char* NegatedDesc() { return "isn't equal to"; }
|
||||
};
|
||||
template <typename Rhs>
|
||||
class NeMatcher : public ComparisonBase<NeMatcher<Rhs>, Rhs, AnyNe> {
|
||||
public:
|
||||
explicit NeMatcher(const Rhs& rhs)
|
||||
: ComparisonBase<NeMatcher<Rhs>, Rhs, AnyNe>(rhs) { }
|
||||
static const char* Desc() { return "isn't equal to"; }
|
||||
static const char* NegatedDesc() { return "is equal to"; }
|
||||
};
|
||||
template <typename Rhs>
|
||||
class LtMatcher : public ComparisonBase<LtMatcher<Rhs>, Rhs, AnyLt> {
|
||||
public:
|
||||
explicit LtMatcher(const Rhs& rhs)
|
||||
: ComparisonBase<LtMatcher<Rhs>, Rhs, AnyLt>(rhs) { }
|
||||
static const char* Desc() { return "is <"; }
|
||||
static const char* NegatedDesc() { return "isn't <"; }
|
||||
};
|
||||
template <typename Rhs>
|
||||
class GtMatcher : public ComparisonBase<GtMatcher<Rhs>, Rhs, AnyGt> {
|
||||
public:
|
||||
explicit GtMatcher(const Rhs& rhs)
|
||||
: ComparisonBase<GtMatcher<Rhs>, Rhs, AnyGt>(rhs) { }
|
||||
static const char* Desc() { return "is >"; }
|
||||
static const char* NegatedDesc() { return "isn't >"; }
|
||||
};
|
||||
template <typename Rhs>
|
||||
class LeMatcher : public ComparisonBase<LeMatcher<Rhs>, Rhs, AnyLe> {
|
||||
public:
|
||||
explicit LeMatcher(const Rhs& rhs)
|
||||
: ComparisonBase<LeMatcher<Rhs>, Rhs, AnyLe>(rhs) { }
|
||||
static const char* Desc() { return "is <="; }
|
||||
static const char* NegatedDesc() { return "isn't <="; }
|
||||
};
|
||||
template <typename Rhs>
|
||||
class GeMatcher : public ComparisonBase<GeMatcher<Rhs>, Rhs, AnyGe> {
|
||||
public:
|
||||
explicit GeMatcher(const Rhs& rhs)
|
||||
: ComparisonBase<GeMatcher<Rhs>, Rhs, AnyGe>(rhs) { }
|
||||
static const char* Desc() { return "is >="; }
|
||||
static const char* NegatedDesc() { return "isn't >="; }
|
||||
};
|
||||
|
||||
// Implements polymorphic matchers MatchesRegex(regex) and
|
||||
// ContainsRegex(regex), which can be used as a Matcher<T> as long as
|
||||
// T can be converted to a string.
|
||||
class MatchesRegexMatcher {
|
||||
public:
|
||||
MatchesRegexMatcher(const RE* regex, bool full_match)
|
||||
: regex_(regex), full_match_(full_match) {}
|
||||
|
||||
#if GTEST_HAS_ABSL
|
||||
bool MatchAndExplain(const absl::string_view& s,
|
||||
MatchResultListener* listener) const {
|
||||
return MatchAndExplain(std::string(s), listener);
|
||||
}
|
||||
#endif // GTEST_HAS_ABSL
|
||||
|
||||
// Accepts pointer types, particularly:
|
||||
// const char*
|
||||
// char*
|
||||
// const wchar_t*
|
||||
// wchar_t*
|
||||
template <typename CharType>
|
||||
bool MatchAndExplain(CharType* s, MatchResultListener* listener) const {
|
||||
return s != nullptr && MatchAndExplain(std::string(s), listener);
|
||||
}
|
||||
|
||||
// Matches anything that can convert to std::string.
|
||||
//
|
||||
// This is a template, not just a plain function with const std::string&,
|
||||
// because absl::string_view has some interfering non-explicit constructors.
|
||||
template <class MatcheeStringType>
|
||||
bool MatchAndExplain(const MatcheeStringType& s,
|
||||
MatchResultListener* /* listener */) const {
|
||||
const std::string& s2(s);
|
||||
return full_match_ ? RE::FullMatch(s2, *regex_)
|
||||
: RE::PartialMatch(s2, *regex_);
|
||||
}
|
||||
|
||||
void DescribeTo(::std::ostream* os) const {
|
||||
*os << (full_match_ ? "matches" : "contains") << " regular expression ";
|
||||
UniversalPrinter<std::string>::Print(regex_->pattern(), os);
|
||||
}
|
||||
|
||||
void DescribeNegationTo(::std::ostream* os) const {
|
||||
*os << "doesn't " << (full_match_ ? "match" : "contain")
|
||||
<< " regular expression ";
|
||||
UniversalPrinter<std::string>::Print(regex_->pattern(), os);
|
||||
}
|
||||
|
||||
private:
|
||||
const std::shared_ptr<const RE> regex_;
|
||||
const bool full_match_;
|
||||
};
|
||||
} // namespace internal
|
||||
|
||||
// Matches a string that fully matches regular expression 'regex'.
|
||||
// The matcher takes ownership of 'regex'.
|
||||
inline PolymorphicMatcher<internal::MatchesRegexMatcher> MatchesRegex(
|
||||
const internal::RE* regex) {
|
||||
return MakePolymorphicMatcher(internal::MatchesRegexMatcher(regex, true));
|
||||
}
|
||||
inline PolymorphicMatcher<internal::MatchesRegexMatcher> MatchesRegex(
|
||||
const std::string& regex) {
|
||||
return MatchesRegex(new internal::RE(regex));
|
||||
}
|
||||
|
||||
// Matches a string that contains regular expression 'regex'.
|
||||
// The matcher takes ownership of 'regex'.
|
||||
inline PolymorphicMatcher<internal::MatchesRegexMatcher> ContainsRegex(
|
||||
const internal::RE* regex) {
|
||||
return MakePolymorphicMatcher(internal::MatchesRegexMatcher(regex, false));
|
||||
}
|
||||
inline PolymorphicMatcher<internal::MatchesRegexMatcher> ContainsRegex(
|
||||
const std::string& regex) {
|
||||
return ContainsRegex(new internal::RE(regex));
|
||||
}
|
||||
|
||||
// Creates a polymorphic matcher that matches anything equal to x.
|
||||
// Note: if the parameter of Eq() were declared as const T&, Eq("foo")
|
||||
// wouldn't compile.
|
||||
template <typename T>
|
||||
inline internal::EqMatcher<T> Eq(T x) { return internal::EqMatcher<T>(x); }
|
||||
|
||||
// Constructs a Matcher<T> from a 'value' of type T. The constructed
|
||||
// matcher matches any value that's equal to 'value'.
|
||||
template <typename T>
|
||||
Matcher<T>::Matcher(T value) { *this = Eq(value); }
|
||||
|
||||
// Creates a monomorphic matcher that matches anything with type Lhs
|
||||
// and equal to rhs. A user may need to use this instead of Eq(...)
|
||||
// in order to resolve an overloading ambiguity.
|
||||
//
|
||||
// TypedEq<T>(x) is just a convenient short-hand for Matcher<T>(Eq(x))
|
||||
// or Matcher<T>(x), but more readable than the latter.
|
||||
//
|
||||
// We could define similar monomorphic matchers for other comparison
|
||||
// operations (e.g. TypedLt, TypedGe, and etc), but decided not to do
|
||||
// it yet as those are used much less than Eq() in practice. A user
|
||||
// can always write Matcher<T>(Lt(5)) to be explicit about the type,
|
||||
// for example.
|
||||
template <typename Lhs, typename Rhs>
|
||||
inline Matcher<Lhs> TypedEq(const Rhs& rhs) { return Eq(rhs); }
|
||||
|
||||
// Creates a polymorphic matcher that matches anything >= x.
|
||||
template <typename Rhs>
|
||||
inline internal::GeMatcher<Rhs> Ge(Rhs x) {
|
||||
return internal::GeMatcher<Rhs>(x);
|
||||
}
|
||||
|
||||
// Creates a polymorphic matcher that matches anything > x.
|
||||
template <typename Rhs>
|
||||
inline internal::GtMatcher<Rhs> Gt(Rhs x) {
|
||||
return internal::GtMatcher<Rhs>(x);
|
||||
}
|
||||
|
||||
// Creates a polymorphic matcher that matches anything <= x.
|
||||
template <typename Rhs>
|
||||
inline internal::LeMatcher<Rhs> Le(Rhs x) {
|
||||
return internal::LeMatcher<Rhs>(x);
|
||||
}
|
||||
|
||||
// Creates a polymorphic matcher that matches anything < x.
|
||||
template <typename Rhs>
|
||||
inline internal::LtMatcher<Rhs> Lt(Rhs x) {
|
||||
return internal::LtMatcher<Rhs>(x);
|
||||
}
|
||||
|
||||
// Creates a polymorphic matcher that matches anything != x.
|
||||
template <typename Rhs>
|
||||
inline internal::NeMatcher<Rhs> Ne(Rhs x) {
|
||||
return internal::NeMatcher<Rhs>(x);
|
||||
}
|
||||
} // namespace testing
|
||||
|
||||
GTEST_DISABLE_MSC_WARNINGS_POP_() // 4251 5046
|
||||
|
||||
#endif // GTEST_INCLUDE_GTEST_GTEST_MATCHERS_H_
|
||||
@@ -1,218 +0,0 @@
|
||||
// Copyright 2005, Google Inc.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
//
|
||||
// The Google C++ Testing and Mocking Framework (Google Test)
|
||||
//
|
||||
// This header file defines the Message class.
|
||||
//
|
||||
// IMPORTANT NOTE: Due to limitation of the C++ language, we have to
|
||||
// leave some internal implementation details in this header file.
|
||||
// They are clearly marked by comments like this:
|
||||
//
|
||||
// // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
|
||||
//
|
||||
// Such code is NOT meant to be used by a user directly, and is subject
|
||||
// to CHANGE WITHOUT NOTICE. Therefore DO NOT DEPEND ON IT in a user
|
||||
// program!
|
||||
|
||||
// GOOGLETEST_CM0001 DO NOT DELETE
|
||||
|
||||
#ifndef GTEST_INCLUDE_GTEST_GTEST_MESSAGE_H_
|
||||
#define GTEST_INCLUDE_GTEST_GTEST_MESSAGE_H_
|
||||
|
||||
#include <limits>
|
||||
#include <memory>
|
||||
|
||||
#include "gtest/internal/gtest-port.h"
|
||||
|
||||
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251 \
|
||||
/* class A needs to have dll-interface to be used by clients of class B */)
|
||||
|
||||
// Ensures that there is at least one operator<< in the global namespace.
|
||||
// See Message& operator<<(...) below for why.
|
||||
void operator<<(const testing::internal::Secret&, int);
|
||||
|
||||
namespace testing {
|
||||
|
||||
// The Message class works like an ostream repeater.
|
||||
//
|
||||
// Typical usage:
|
||||
//
|
||||
// 1. You stream a bunch of values to a Message object.
|
||||
// It will remember the text in a stringstream.
|
||||
// 2. Then you stream the Message object to an ostream.
|
||||
// This causes the text in the Message to be streamed
|
||||
// to the ostream.
|
||||
//
|
||||
// For example;
|
||||
//
|
||||
// testing::Message foo;
|
||||
// foo << 1 << " != " << 2;
|
||||
// std::cout << foo;
|
||||
//
|
||||
// will print "1 != 2".
|
||||
//
|
||||
// Message is not intended to be inherited from. In particular, its
|
||||
// destructor is not virtual.
|
||||
//
|
||||
// Note that stringstream behaves differently in gcc and in MSVC. You
|
||||
// can stream a NULL char pointer to it in the former, but not in the
|
||||
// latter (it causes an access violation if you do). The Message
|
||||
// class hides this difference by treating a NULL char pointer as
|
||||
// "(null)".
|
||||
class GTEST_API_ Message {
|
||||
private:
|
||||
// The type of basic IO manipulators (endl, ends, and flush) for
|
||||
// narrow streams.
|
||||
typedef std::ostream& (*BasicNarrowIoManip)(std::ostream&);
|
||||
|
||||
public:
|
||||
// Constructs an empty Message.
|
||||
Message();
|
||||
|
||||
// Copy constructor.
|
||||
Message(const Message& msg) : ss_(new ::std::stringstream) { // NOLINT
|
||||
*ss_ << msg.GetString();
|
||||
}
|
||||
|
||||
// Constructs a Message from a C-string.
|
||||
explicit Message(const char* str) : ss_(new ::std::stringstream) {
|
||||
*ss_ << str;
|
||||
}
|
||||
|
||||
// Streams a non-pointer value to this object.
|
||||
template <typename T>
|
||||
inline Message& operator <<(const T& val) {
|
||||
// Some libraries overload << for STL containers. These
|
||||
// overloads are defined in the global namespace instead of ::std.
|
||||
//
|
||||
// C++'s symbol lookup rule (i.e. Koenig lookup) says that these
|
||||
// overloads are visible in either the std namespace or the global
|
||||
// namespace, but not other namespaces, including the testing
|
||||
// namespace which Google Test's Message class is in.
|
||||
//
|
||||
// To allow STL containers (and other types that has a << operator
|
||||
// defined in the global namespace) to be used in Google Test
|
||||
// assertions, testing::Message must access the custom << operator
|
||||
// from the global namespace. With this using declaration,
|
||||
// overloads of << defined in the global namespace and those
|
||||
// visible via Koenig lookup are both exposed in this function.
|
||||
using ::operator <<;
|
||||
*ss_ << val;
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Streams a pointer value to this object.
|
||||
//
|
||||
// This function is an overload of the previous one. When you
|
||||
// stream a pointer to a Message, this definition will be used as it
|
||||
// is more specialized. (The C++ Standard, section
|
||||
// [temp.func.order].) If you stream a non-pointer, then the
|
||||
// previous definition will be used.
|
||||
//
|
||||
// The reason for this overload is that streaming a NULL pointer to
|
||||
// ostream is undefined behavior. Depending on the compiler, you
|
||||
// may get "0", "(nil)", "(null)", or an access violation. To
|
||||
// ensure consistent result across compilers, we always treat NULL
|
||||
// as "(null)".
|
||||
template <typename T>
|
||||
inline Message& operator <<(T* const& pointer) { // NOLINT
|
||||
if (pointer == nullptr) {
|
||||
*ss_ << "(null)";
|
||||
} else {
|
||||
*ss_ << pointer;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Since the basic IO manipulators are overloaded for both narrow
|
||||
// and wide streams, we have to provide this specialized definition
|
||||
// of operator <<, even though its body is the same as the
|
||||
// templatized version above. Without this definition, streaming
|
||||
// endl or other basic IO manipulators to Message will confuse the
|
||||
// compiler.
|
||||
Message& operator <<(BasicNarrowIoManip val) {
|
||||
*ss_ << val;
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Instead of 1/0, we want to see true/false for bool values.
|
||||
Message& operator <<(bool b) {
|
||||
return *this << (b ? "true" : "false");
|
||||
}
|
||||
|
||||
// These two overloads allow streaming a wide C string to a Message
|
||||
// using the UTF-8 encoding.
|
||||
Message& operator <<(const wchar_t* wide_c_str);
|
||||
Message& operator <<(wchar_t* wide_c_str);
|
||||
|
||||
#if GTEST_HAS_STD_WSTRING
|
||||
// Converts the given wide string to a narrow string using the UTF-8
|
||||
// encoding, and streams the result to this Message object.
|
||||
Message& operator <<(const ::std::wstring& wstr);
|
||||
#endif // GTEST_HAS_STD_WSTRING
|
||||
|
||||
// Gets the text streamed to this object so far as an std::string.
|
||||
// Each '\0' character in the buffer is replaced with "\\0".
|
||||
//
|
||||
// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
|
||||
std::string GetString() const;
|
||||
|
||||
private:
|
||||
// We'll hold the text streamed to this object here.
|
||||
const std::unique_ptr< ::std::stringstream> ss_;
|
||||
|
||||
// We declare (but don't implement) this to prevent the compiler
|
||||
// from implementing the assignment operator.
|
||||
void operator=(const Message&);
|
||||
};
|
||||
|
||||
// Streams a Message to an ostream.
|
||||
inline std::ostream& operator <<(std::ostream& os, const Message& sb) {
|
||||
return os << sb.GetString();
|
||||
}
|
||||
|
||||
namespace internal {
|
||||
|
||||
// Converts a streamable value to an std::string. A NULL pointer is
|
||||
// converted to "(null)". When the input value is a ::string,
|
||||
// ::std::string, ::wstring, or ::std::wstring object, each NUL
|
||||
// character in it is replaced with "\\0".
|
||||
template <typename T>
|
||||
std::string StreamableToString(const T& streamable) {
|
||||
return (Message() << streamable).GetString();
|
||||
}
|
||||
|
||||
} // namespace internal
|
||||
} // namespace testing
|
||||
|
||||
GTEST_DISABLE_MSC_WARNINGS_POP_() // 4251
|
||||
|
||||
#endif // GTEST_INCLUDE_GTEST_GTEST_MESSAGE_H_
|
||||
@@ -1,503 +0,0 @@
|
||||
// Copyright 2008, Google Inc.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Macros and functions for implementing parameterized tests
|
||||
// in Google C++ Testing and Mocking Framework (Google Test)
|
||||
//
|
||||
// This file is generated by a SCRIPT. DO NOT EDIT BY HAND!
|
||||
//
|
||||
// GOOGLETEST_CM0001 DO NOT DELETE
|
||||
#ifndef GTEST_INCLUDE_GTEST_GTEST_PARAM_TEST_H_
|
||||
#define GTEST_INCLUDE_GTEST_GTEST_PARAM_TEST_H_
|
||||
|
||||
|
||||
// Value-parameterized tests allow you to test your code with different
|
||||
// parameters without writing multiple copies of the same test.
|
||||
//
|
||||
// Here is how you use value-parameterized tests:
|
||||
|
||||
#if 0
|
||||
|
||||
// To write value-parameterized tests, first you should define a fixture
|
||||
// class. It is usually derived from testing::TestWithParam<T> (see below for
|
||||
// another inheritance scheme that's sometimes useful in more complicated
|
||||
// class hierarchies), where the type of your parameter values.
|
||||
// TestWithParam<T> is itself derived from testing::Test. T can be any
|
||||
// copyable type. If it's a raw pointer, you are responsible for managing the
|
||||
// lifespan of the pointed values.
|
||||
|
||||
class FooTest : public ::testing::TestWithParam<const char*> {
|
||||
// You can implement all the usual class fixture members here.
|
||||
};
|
||||
|
||||
// Then, use the TEST_P macro to define as many parameterized tests
|
||||
// for this fixture as you want. The _P suffix is for "parameterized"
|
||||
// or "pattern", whichever you prefer to think.
|
||||
|
||||
TEST_P(FooTest, DoesBlah) {
|
||||
// Inside a test, access the test parameter with the GetParam() method
|
||||
// of the TestWithParam<T> class:
|
||||
EXPECT_TRUE(foo.Blah(GetParam()));
|
||||
...
|
||||
}
|
||||
|
||||
TEST_P(FooTest, HasBlahBlah) {
|
||||
...
|
||||
}
|
||||
|
||||
// Finally, you can use INSTANTIATE_TEST_SUITE_P to instantiate the test
|
||||
// case with any set of parameters you want. Google Test defines a number
|
||||
// of functions for generating test parameters. They return what we call
|
||||
// (surprise!) parameter generators. Here is a summary of them, which
|
||||
// are all in the testing namespace:
|
||||
//
|
||||
//
|
||||
// Range(begin, end [, step]) - Yields values {begin, begin+step,
|
||||
// begin+step+step, ...}. The values do not
|
||||
// include end. step defaults to 1.
|
||||
// Values(v1, v2, ..., vN) - Yields values {v1, v2, ..., vN}.
|
||||
// ValuesIn(container) - Yields values from a C-style array, an STL
|
||||
// ValuesIn(begin,end) container, or an iterator range [begin, end).
|
||||
// Bool() - Yields sequence {false, true}.
|
||||
// Combine(g1, g2, ..., gN) - Yields all combinations (the Cartesian product
|
||||
// for the math savvy) of the values generated
|
||||
// by the N generators.
|
||||
//
|
||||
// For more details, see comments at the definitions of these functions below
|
||||
// in this file.
|
||||
//
|
||||
// The following statement will instantiate tests from the FooTest test suite
|
||||
// each with parameter values "meeny", "miny", and "moe".
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(InstantiationName,
|
||||
FooTest,
|
||||
Values("meeny", "miny", "moe"));
|
||||
|
||||
// To distinguish different instances of the pattern, (yes, you
|
||||
// can instantiate it more than once) the first argument to the
|
||||
// INSTANTIATE_TEST_SUITE_P macro is a prefix that will be added to the
|
||||
// actual test suite name. Remember to pick unique prefixes for different
|
||||
// instantiations. The tests from the instantiation above will have
|
||||
// these names:
|
||||
//
|
||||
// * InstantiationName/FooTest.DoesBlah/0 for "meeny"
|
||||
// * InstantiationName/FooTest.DoesBlah/1 for "miny"
|
||||
// * InstantiationName/FooTest.DoesBlah/2 for "moe"
|
||||
// * InstantiationName/FooTest.HasBlahBlah/0 for "meeny"
|
||||
// * InstantiationName/FooTest.HasBlahBlah/1 for "miny"
|
||||
// * InstantiationName/FooTest.HasBlahBlah/2 for "moe"
|
||||
//
|
||||
// You can use these names in --gtest_filter.
|
||||
//
|
||||
// This statement will instantiate all tests from FooTest again, each
|
||||
// with parameter values "cat" and "dog":
|
||||
|
||||
const char* pets[] = {"cat", "dog"};
|
||||
INSTANTIATE_TEST_SUITE_P(AnotherInstantiationName, FooTest, ValuesIn(pets));
|
||||
|
||||
// The tests from the instantiation above will have these names:
|
||||
//
|
||||
// * AnotherInstantiationName/FooTest.DoesBlah/0 for "cat"
|
||||
// * AnotherInstantiationName/FooTest.DoesBlah/1 for "dog"
|
||||
// * AnotherInstantiationName/FooTest.HasBlahBlah/0 for "cat"
|
||||
// * AnotherInstantiationName/FooTest.HasBlahBlah/1 for "dog"
|
||||
//
|
||||
// Please note that INSTANTIATE_TEST_SUITE_P will instantiate all tests
|
||||
// in the given test suite, whether their definitions come before or
|
||||
// AFTER the INSTANTIATE_TEST_SUITE_P statement.
|
||||
//
|
||||
// Please also note that generator expressions (including parameters to the
|
||||
// generators) are evaluated in InitGoogleTest(), after main() has started.
|
||||
// This allows the user on one hand, to adjust generator parameters in order
|
||||
// to dynamically determine a set of tests to run and on the other hand,
|
||||
// give the user a chance to inspect the generated tests with Google Test
|
||||
// reflection API before RUN_ALL_TESTS() is executed.
|
||||
//
|
||||
// You can see samples/sample7_unittest.cc and samples/sample8_unittest.cc
|
||||
// for more examples.
|
||||
//
|
||||
// In the future, we plan to publish the API for defining new parameter
|
||||
// generators. But for now this interface remains part of the internal
|
||||
// implementation and is subject to change.
|
||||
//
|
||||
//
|
||||
// A parameterized test fixture must be derived from testing::Test and from
|
||||
// testing::WithParamInterface<T>, where T is the type of the parameter
|
||||
// values. Inheriting from TestWithParam<T> satisfies that requirement because
|
||||
// TestWithParam<T> inherits from both Test and WithParamInterface. In more
|
||||
// complicated hierarchies, however, it is occasionally useful to inherit
|
||||
// separately from Test and WithParamInterface. For example:
|
||||
|
||||
class BaseTest : public ::testing::Test {
|
||||
// You can inherit all the usual members for a non-parameterized test
|
||||
// fixture here.
|
||||
};
|
||||
|
||||
class DerivedTest : public BaseTest, public ::testing::WithParamInterface<int> {
|
||||
// The usual test fixture members go here too.
|
||||
};
|
||||
|
||||
TEST_F(BaseTest, HasFoo) {
|
||||
// This is an ordinary non-parameterized test.
|
||||
}
|
||||
|
||||
TEST_P(DerivedTest, DoesBlah) {
|
||||
// GetParam works just the same here as if you inherit from TestWithParam.
|
||||
EXPECT_TRUE(foo.Blah(GetParam()));
|
||||
}
|
||||
|
||||
#endif // 0
|
||||
|
||||
#include <iterator>
|
||||
#include <utility>
|
||||
|
||||
#include "gtest/internal/gtest-internal.h"
|
||||
#include "gtest/internal/gtest-param-util.h"
|
||||
#include "gtest/internal/gtest-port.h"
|
||||
|
||||
namespace testing {
|
||||
|
||||
// Functions producing parameter generators.
|
||||
//
|
||||
// Google Test uses these generators to produce parameters for value-
|
||||
// parameterized tests. When a parameterized test suite is instantiated
|
||||
// with a particular generator, Google Test creates and runs tests
|
||||
// for each element in the sequence produced by the generator.
|
||||
//
|
||||
// In the following sample, tests from test suite FooTest are instantiated
|
||||
// each three times with parameter values 3, 5, and 8:
|
||||
//
|
||||
// class FooTest : public TestWithParam<int> { ... };
|
||||
//
|
||||
// TEST_P(FooTest, TestThis) {
|
||||
// }
|
||||
// TEST_P(FooTest, TestThat) {
|
||||
// }
|
||||
// INSTANTIATE_TEST_SUITE_P(TestSequence, FooTest, Values(3, 5, 8));
|
||||
//
|
||||
|
||||
// Range() returns generators providing sequences of values in a range.
|
||||
//
|
||||
// Synopsis:
|
||||
// Range(start, end)
|
||||
// - returns a generator producing a sequence of values {start, start+1,
|
||||
// start+2, ..., }.
|
||||
// Range(start, end, step)
|
||||
// - returns a generator producing a sequence of values {start, start+step,
|
||||
// start+step+step, ..., }.
|
||||
// Notes:
|
||||
// * The generated sequences never include end. For example, Range(1, 5)
|
||||
// returns a generator producing a sequence {1, 2, 3, 4}. Range(1, 9, 2)
|
||||
// returns a generator producing {1, 3, 5, 7}.
|
||||
// * start and end must have the same type. That type may be any integral or
|
||||
// floating-point type or a user defined type satisfying these conditions:
|
||||
// * It must be assignable (have operator=() defined).
|
||||
// * It must have operator+() (operator+(int-compatible type) for
|
||||
// two-operand version).
|
||||
// * It must have operator<() defined.
|
||||
// Elements in the resulting sequences will also have that type.
|
||||
// * Condition start < end must be satisfied in order for resulting sequences
|
||||
// to contain any elements.
|
||||
//
|
||||
template <typename T, typename IncrementT>
|
||||
internal::ParamGenerator<T> Range(T start, T end, IncrementT step) {
|
||||
return internal::ParamGenerator<T>(
|
||||
new internal::RangeGenerator<T, IncrementT>(start, end, step));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
internal::ParamGenerator<T> Range(T start, T end) {
|
||||
return Range(start, end, 1);
|
||||
}
|
||||
|
||||
// ValuesIn() function allows generation of tests with parameters coming from
|
||||
// a container.
|
||||
//
|
||||
// Synopsis:
|
||||
// ValuesIn(const T (&array)[N])
|
||||
// - returns a generator producing sequences with elements from
|
||||
// a C-style array.
|
||||
// ValuesIn(const Container& container)
|
||||
// - returns a generator producing sequences with elements from
|
||||
// an STL-style container.
|
||||
// ValuesIn(Iterator begin, Iterator end)
|
||||
// - returns a generator producing sequences with elements from
|
||||
// a range [begin, end) defined by a pair of STL-style iterators. These
|
||||
// iterators can also be plain C pointers.
|
||||
//
|
||||
// Please note that ValuesIn copies the values from the containers
|
||||
// passed in and keeps them to generate tests in RUN_ALL_TESTS().
|
||||
//
|
||||
// Examples:
|
||||
//
|
||||
// This instantiates tests from test suite StringTest
|
||||
// each with C-string values of "foo", "bar", and "baz":
|
||||
//
|
||||
// const char* strings[] = {"foo", "bar", "baz"};
|
||||
// INSTANTIATE_TEST_SUITE_P(StringSequence, StringTest, ValuesIn(strings));
|
||||
//
|
||||
// This instantiates tests from test suite StlStringTest
|
||||
// each with STL strings with values "a" and "b":
|
||||
//
|
||||
// ::std::vector< ::std::string> GetParameterStrings() {
|
||||
// ::std::vector< ::std::string> v;
|
||||
// v.push_back("a");
|
||||
// v.push_back("b");
|
||||
// return v;
|
||||
// }
|
||||
//
|
||||
// INSTANTIATE_TEST_SUITE_P(CharSequence,
|
||||
// StlStringTest,
|
||||
// ValuesIn(GetParameterStrings()));
|
||||
//
|
||||
//
|
||||
// This will also instantiate tests from CharTest
|
||||
// each with parameter values 'a' and 'b':
|
||||
//
|
||||
// ::std::list<char> GetParameterChars() {
|
||||
// ::std::list<char> list;
|
||||
// list.push_back('a');
|
||||
// list.push_back('b');
|
||||
// return list;
|
||||
// }
|
||||
// ::std::list<char> l = GetParameterChars();
|
||||
// INSTANTIATE_TEST_SUITE_P(CharSequence2,
|
||||
// CharTest,
|
||||
// ValuesIn(l.begin(), l.end()));
|
||||
//
|
||||
template <typename ForwardIterator>
|
||||
internal::ParamGenerator<
|
||||
typename std::iterator_traits<ForwardIterator>::value_type>
|
||||
ValuesIn(ForwardIterator begin, ForwardIterator end) {
|
||||
typedef typename std::iterator_traits<ForwardIterator>::value_type ParamType;
|
||||
return internal::ParamGenerator<ParamType>(
|
||||
new internal::ValuesInIteratorRangeGenerator<ParamType>(begin, end));
|
||||
}
|
||||
|
||||
template <typename T, size_t N>
|
||||
internal::ParamGenerator<T> ValuesIn(const T (&array)[N]) {
|
||||
return ValuesIn(array, array + N);
|
||||
}
|
||||
|
||||
template <class Container>
|
||||
internal::ParamGenerator<typename Container::value_type> ValuesIn(
|
||||
const Container& container) {
|
||||
return ValuesIn(container.begin(), container.end());
|
||||
}
|
||||
|
||||
// Values() allows generating tests from explicitly specified list of
|
||||
// parameters.
|
||||
//
|
||||
// Synopsis:
|
||||
// Values(T v1, T v2, ..., T vN)
|
||||
// - returns a generator producing sequences with elements v1, v2, ..., vN.
|
||||
//
|
||||
// For example, this instantiates tests from test suite BarTest each
|
||||
// with values "one", "two", and "three":
|
||||
//
|
||||
// INSTANTIATE_TEST_SUITE_P(NumSequence,
|
||||
// BarTest,
|
||||
// Values("one", "two", "three"));
|
||||
//
|
||||
// This instantiates tests from test suite BazTest each with values 1, 2, 3.5.
|
||||
// The exact type of values will depend on the type of parameter in BazTest.
|
||||
//
|
||||
// INSTANTIATE_TEST_SUITE_P(FloatingNumbers, BazTest, Values(1, 2, 3.5));
|
||||
//
|
||||
//
|
||||
template <typename... T>
|
||||
internal::ValueArray<T...> Values(T... v) {
|
||||
return internal::ValueArray<T...>(std::move(v)...);
|
||||
}
|
||||
|
||||
// Bool() allows generating tests with parameters in a set of (false, true).
|
||||
//
|
||||
// Synopsis:
|
||||
// Bool()
|
||||
// - returns a generator producing sequences with elements {false, true}.
|
||||
//
|
||||
// It is useful when testing code that depends on Boolean flags. Combinations
|
||||
// of multiple flags can be tested when several Bool()'s are combined using
|
||||
// Combine() function.
|
||||
//
|
||||
// In the following example all tests in the test suite FlagDependentTest
|
||||
// will be instantiated twice with parameters false and true.
|
||||
//
|
||||
// class FlagDependentTest : public testing::TestWithParam<bool> {
|
||||
// virtual void SetUp() {
|
||||
// external_flag = GetParam();
|
||||
// }
|
||||
// }
|
||||
// INSTANTIATE_TEST_SUITE_P(BoolSequence, FlagDependentTest, Bool());
|
||||
//
|
||||
inline internal::ParamGenerator<bool> Bool() {
|
||||
return Values(false, true);
|
||||
}
|
||||
|
||||
// Combine() allows the user to combine two or more sequences to produce
|
||||
// values of a Cartesian product of those sequences' elements.
|
||||
//
|
||||
// Synopsis:
|
||||
// Combine(gen1, gen2, ..., genN)
|
||||
// - returns a generator producing sequences with elements coming from
|
||||
// the Cartesian product of elements from the sequences generated by
|
||||
// gen1, gen2, ..., genN. The sequence elements will have a type of
|
||||
// std::tuple<T1, T2, ..., TN> where T1, T2, ..., TN are the types
|
||||
// of elements from sequences produces by gen1, gen2, ..., genN.
|
||||
//
|
||||
// Combine can have up to 10 arguments.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// This will instantiate tests in test suite AnimalTest each one with
|
||||
// the parameter values tuple("cat", BLACK), tuple("cat", WHITE),
|
||||
// tuple("dog", BLACK), and tuple("dog", WHITE):
|
||||
//
|
||||
// enum Color { BLACK, GRAY, WHITE };
|
||||
// class AnimalTest
|
||||
// : public testing::TestWithParam<std::tuple<const char*, Color> > {...};
|
||||
//
|
||||
// TEST_P(AnimalTest, AnimalLooksNice) {...}
|
||||
//
|
||||
// INSTANTIATE_TEST_SUITE_P(AnimalVariations, AnimalTest,
|
||||
// Combine(Values("cat", "dog"),
|
||||
// Values(BLACK, WHITE)));
|
||||
//
|
||||
// This will instantiate tests in FlagDependentTest with all variations of two
|
||||
// Boolean flags:
|
||||
//
|
||||
// class FlagDependentTest
|
||||
// : public testing::TestWithParam<std::tuple<bool, bool> > {
|
||||
// virtual void SetUp() {
|
||||
// // Assigns external_flag_1 and external_flag_2 values from the tuple.
|
||||
// std::tie(external_flag_1, external_flag_2) = GetParam();
|
||||
// }
|
||||
// };
|
||||
//
|
||||
// TEST_P(FlagDependentTest, TestFeature1) {
|
||||
// // Test your code using external_flag_1 and external_flag_2 here.
|
||||
// }
|
||||
// INSTANTIATE_TEST_SUITE_P(TwoBoolSequence, FlagDependentTest,
|
||||
// Combine(Bool(), Bool()));
|
||||
//
|
||||
template <typename... Generator>
|
||||
internal::CartesianProductHolder<Generator...> Combine(const Generator&... g) {
|
||||
return internal::CartesianProductHolder<Generator...>(g...);
|
||||
}
|
||||
|
||||
#define TEST_P(test_suite_name, test_name) \
|
||||
class GTEST_TEST_CLASS_NAME_(test_suite_name, test_name) \
|
||||
: public test_suite_name { \
|
||||
public: \
|
||||
GTEST_TEST_CLASS_NAME_(test_suite_name, test_name)() {} \
|
||||
virtual void TestBody(); \
|
||||
\
|
||||
private: \
|
||||
static int AddToRegistry() { \
|
||||
::testing::UnitTest::GetInstance() \
|
||||
->parameterized_test_registry() \
|
||||
.GetTestSuitePatternHolder<test_suite_name>( \
|
||||
#test_suite_name, \
|
||||
::testing::internal::CodeLocation(__FILE__, __LINE__)) \
|
||||
->AddTestPattern( \
|
||||
GTEST_STRINGIFY_(test_suite_name), GTEST_STRINGIFY_(test_name), \
|
||||
new ::testing::internal::TestMetaFactory<GTEST_TEST_CLASS_NAME_( \
|
||||
test_suite_name, test_name)>()); \
|
||||
return 0; \
|
||||
} \
|
||||
static int gtest_registering_dummy_ GTEST_ATTRIBUTE_UNUSED_; \
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(GTEST_TEST_CLASS_NAME_(test_suite_name, \
|
||||
test_name)); \
|
||||
}; \
|
||||
int GTEST_TEST_CLASS_NAME_(test_suite_name, \
|
||||
test_name)::gtest_registering_dummy_ = \
|
||||
GTEST_TEST_CLASS_NAME_(test_suite_name, test_name)::AddToRegistry(); \
|
||||
void GTEST_TEST_CLASS_NAME_(test_suite_name, test_name)::TestBody()
|
||||
|
||||
// The last argument to INSTANTIATE_TEST_SUITE_P allows the user to specify
|
||||
// generator and an optional function or functor that generates custom test name
|
||||
// suffixes based on the test parameters. Such a function or functor should
|
||||
// accept one argument of type testing::TestParamInfo<class ParamType>, and
|
||||
// return std::string.
|
||||
//
|
||||
// testing::PrintToStringParamName is a builtin test suffix generator that
|
||||
// returns the value of testing::PrintToString(GetParam()).
|
||||
//
|
||||
// Note: test names must be non-empty, unique, and may only contain ASCII
|
||||
// alphanumeric characters or underscore. Because PrintToString adds quotes
|
||||
// to std::string and C strings, it won't work for these types.
|
||||
|
||||
#define GTEST_EXPAND_(arg) arg
|
||||
#define GTEST_GET_FIRST_(first, ...) first
|
||||
#define GTEST_GET_SECOND_(first, second, ...) second
|
||||
|
||||
#define INSTANTIATE_TEST_SUITE_P(prefix, test_suite_name, ...) \
|
||||
static ::testing::internal::ParamGenerator<test_suite_name::ParamType> \
|
||||
gtest_##prefix##test_suite_name##_EvalGenerator_() { \
|
||||
return GTEST_EXPAND_(GTEST_GET_FIRST_(__VA_ARGS__, DUMMY_PARAM_)); \
|
||||
} \
|
||||
static ::std::string gtest_##prefix##test_suite_name##_EvalGenerateName_( \
|
||||
const ::testing::TestParamInfo<test_suite_name::ParamType>& info) { \
|
||||
if (::testing::internal::AlwaysFalse()) { \
|
||||
::testing::internal::TestNotEmpty(GTEST_EXPAND_(GTEST_GET_SECOND_( \
|
||||
__VA_ARGS__, \
|
||||
::testing::internal::DefaultParamName<test_suite_name::ParamType>, \
|
||||
DUMMY_PARAM_))); \
|
||||
auto t = std::make_tuple(__VA_ARGS__); \
|
||||
static_assert(std::tuple_size<decltype(t)>::value <= 2, \
|
||||
"Too Many Args!"); \
|
||||
} \
|
||||
return ((GTEST_EXPAND_(GTEST_GET_SECOND_( \
|
||||
__VA_ARGS__, \
|
||||
::testing::internal::DefaultParamName<test_suite_name::ParamType>, \
|
||||
DUMMY_PARAM_))))(info); \
|
||||
} \
|
||||
static int gtest_##prefix##test_suite_name##_dummy_ \
|
||||
GTEST_ATTRIBUTE_UNUSED_ = \
|
||||
::testing::UnitTest::GetInstance() \
|
||||
->parameterized_test_registry() \
|
||||
.GetTestSuitePatternHolder<test_suite_name>( \
|
||||
#test_suite_name, \
|
||||
::testing::internal::CodeLocation(__FILE__, __LINE__)) \
|
||||
->AddTestSuiteInstantiation( \
|
||||
#prefix, >est_##prefix##test_suite_name##_EvalGenerator_, \
|
||||
>est_##prefix##test_suite_name##_EvalGenerateName_, \
|
||||
__FILE__, __LINE__)
|
||||
|
||||
// Legacy API is deprecated but still available
|
||||
#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
|
||||
#define INSTANTIATE_TEST_CASE_P \
|
||||
static_assert(::testing::internal::InstantiateTestCase_P_IsDeprecated(), \
|
||||
""); \
|
||||
INSTANTIATE_TEST_SUITE_P
|
||||
#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
|
||||
|
||||
} // namespace testing
|
||||
|
||||
#endif // GTEST_INCLUDE_GTEST_GTEST_PARAM_TEST_H_
|
||||
@@ -1,928 +0,0 @@
|
||||
// Copyright 2007, Google Inc.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
|
||||
// Google Test - The Google C++ Testing and Mocking Framework
|
||||
//
|
||||
// This file implements a universal value printer that can print a
|
||||
// value of any type T:
|
||||
//
|
||||
// void ::testing::internal::UniversalPrinter<T>::Print(value, ostream_ptr);
|
||||
//
|
||||
// A user can teach this function how to print a class type T by
|
||||
// defining either operator<<() or PrintTo() in the namespace that
|
||||
// defines T. More specifically, the FIRST defined function in the
|
||||
// following list will be used (assuming T is defined in namespace
|
||||
// foo):
|
||||
//
|
||||
// 1. foo::PrintTo(const T&, ostream*)
|
||||
// 2. operator<<(ostream&, const T&) defined in either foo or the
|
||||
// global namespace.
|
||||
//
|
||||
// However if T is an STL-style container then it is printed element-wise
|
||||
// unless foo::PrintTo(const T&, ostream*) is defined. Note that
|
||||
// operator<<() is ignored for container types.
|
||||
//
|
||||
// If none of the above is defined, it will print the debug string of
|
||||
// the value if it is a protocol buffer, or print the raw bytes in the
|
||||
// value otherwise.
|
||||
//
|
||||
// To aid debugging: when T is a reference type, the address of the
|
||||
// value is also printed; when T is a (const) char pointer, both the
|
||||
// pointer value and the NUL-terminated string it points to are
|
||||
// printed.
|
||||
//
|
||||
// We also provide some convenient wrappers:
|
||||
//
|
||||
// // Prints a value to a string. For a (const or not) char
|
||||
// // pointer, the NUL-terminated string (but not the pointer) is
|
||||
// // printed.
|
||||
// std::string ::testing::PrintToString(const T& value);
|
||||
//
|
||||
// // Prints a value tersely: for a reference type, the referenced
|
||||
// // value (but not the address) is printed; for a (const or not) char
|
||||
// // pointer, the NUL-terminated string (but not the pointer) is
|
||||
// // printed.
|
||||
// void ::testing::internal::UniversalTersePrint(const T& value, ostream*);
|
||||
//
|
||||
// // Prints value using the type inferred by the compiler. The difference
|
||||
// // from UniversalTersePrint() is that this function prints both the
|
||||
// // pointer and the NUL-terminated string for a (const or not) char pointer.
|
||||
// void ::testing::internal::UniversalPrint(const T& value, ostream*);
|
||||
//
|
||||
// // Prints the fields of a tuple tersely to a string vector, one
|
||||
// // element for each field. Tuple support must be enabled in
|
||||
// // gtest-port.h.
|
||||
// std::vector<string> UniversalTersePrintTupleFieldsToStrings(
|
||||
// const Tuple& value);
|
||||
//
|
||||
// Known limitation:
|
||||
//
|
||||
// The print primitives print the elements of an STL-style container
|
||||
// using the compiler-inferred type of *iter where iter is a
|
||||
// const_iterator of the container. When const_iterator is an input
|
||||
// iterator but not a forward iterator, this inferred type may not
|
||||
// match value_type, and the print output may be incorrect. In
|
||||
// practice, this is rarely a problem as for most containers
|
||||
// const_iterator is a forward iterator. We'll fix this if there's an
|
||||
// actual need for it. Note that this fix cannot rely on value_type
|
||||
// being defined as many user-defined container types don't have
|
||||
// value_type.
|
||||
|
||||
// GOOGLETEST_CM0001 DO NOT DELETE
|
||||
|
||||
#ifndef GTEST_INCLUDE_GTEST_GTEST_PRINTERS_H_
|
||||
#define GTEST_INCLUDE_GTEST_GTEST_PRINTERS_H_
|
||||
|
||||
#include <functional>
|
||||
#include <ostream> // NOLINT
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <tuple>
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include "gtest/internal/gtest-internal.h"
|
||||
#include "gtest/internal/gtest-port.h"
|
||||
|
||||
#if GTEST_HAS_ABSL
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "absl/types/optional.h"
|
||||
#include "absl/types/variant.h"
|
||||
#endif // GTEST_HAS_ABSL
|
||||
|
||||
namespace testing {
|
||||
|
||||
// Definitions in the 'internal' and 'internal2' name spaces are
|
||||
// subject to change without notice. DO NOT USE THEM IN USER CODE!
|
||||
namespace internal2 {
|
||||
|
||||
// Prints the given number of bytes in the given object to the given
|
||||
// ostream.
|
||||
GTEST_API_ void PrintBytesInObjectTo(const unsigned char* obj_bytes,
|
||||
size_t count,
|
||||
::std::ostream* os);
|
||||
|
||||
// For selecting which printer to use when a given type has neither <<
|
||||
// nor PrintTo().
|
||||
enum TypeKind {
|
||||
kProtobuf, // a protobuf type
|
||||
kConvertibleToInteger, // a type implicitly convertible to BiggestInt
|
||||
// (e.g. a named or unnamed enum type)
|
||||
#if GTEST_HAS_ABSL
|
||||
kConvertibleToStringView, // a type implicitly convertible to
|
||||
// absl::string_view
|
||||
#endif
|
||||
kOtherType // anything else
|
||||
};
|
||||
|
||||
// TypeWithoutFormatter<T, kTypeKind>::PrintValue(value, os) is called
|
||||
// by the universal printer to print a value of type T when neither
|
||||
// operator<< nor PrintTo() is defined for T, where kTypeKind is the
|
||||
// "kind" of T as defined by enum TypeKind.
|
||||
template <typename T, TypeKind kTypeKind>
|
||||
class TypeWithoutFormatter {
|
||||
public:
|
||||
// This default version is called when kTypeKind is kOtherType.
|
||||
static void PrintValue(const T& value, ::std::ostream* os) {
|
||||
PrintBytesInObjectTo(
|
||||
static_cast<const unsigned char*>(
|
||||
reinterpret_cast<const void*>(std::addressof(value))),
|
||||
sizeof(value), os);
|
||||
}
|
||||
};
|
||||
|
||||
// We print a protobuf using its ShortDebugString() when the string
|
||||
// doesn't exceed this many characters; otherwise we print it using
|
||||
// DebugString() for better readability.
|
||||
const size_t kProtobufOneLinerMaxLength = 50;
|
||||
|
||||
template <typename T>
|
||||
class TypeWithoutFormatter<T, kProtobuf> {
|
||||
public:
|
||||
static void PrintValue(const T& value, ::std::ostream* os) {
|
||||
std::string pretty_str = value.ShortDebugString();
|
||||
if (pretty_str.length() > kProtobufOneLinerMaxLength) {
|
||||
pretty_str = "\n" + value.DebugString();
|
||||
}
|
||||
*os << ("<" + pretty_str + ">");
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
class TypeWithoutFormatter<T, kConvertibleToInteger> {
|
||||
public:
|
||||
// Since T has no << operator or PrintTo() but can be implicitly
|
||||
// converted to BiggestInt, we print it as a BiggestInt.
|
||||
//
|
||||
// Most likely T is an enum type (either named or unnamed), in which
|
||||
// case printing it as an integer is the desired behavior. In case
|
||||
// T is not an enum, printing it as an integer is the best we can do
|
||||
// given that it has no user-defined printer.
|
||||
static void PrintValue(const T& value, ::std::ostream* os) {
|
||||
const internal::BiggestInt kBigInt = value;
|
||||
*os << kBigInt;
|
||||
}
|
||||
};
|
||||
|
||||
#if GTEST_HAS_ABSL
|
||||
template <typename T>
|
||||
class TypeWithoutFormatter<T, kConvertibleToStringView> {
|
||||
public:
|
||||
// Since T has neither operator<< nor PrintTo() but can be implicitly
|
||||
// converted to absl::string_view, we print it as a absl::string_view.
|
||||
//
|
||||
// Note: the implementation is further below, as it depends on
|
||||
// internal::PrintTo symbol which is defined later in the file.
|
||||
static void PrintValue(const T& value, ::std::ostream* os);
|
||||
};
|
||||
#endif
|
||||
|
||||
// Prints the given value to the given ostream. If the value is a
|
||||
// protocol message, its debug string is printed; if it's an enum or
|
||||
// of a type implicitly convertible to BiggestInt, it's printed as an
|
||||
// integer; otherwise the bytes in the value are printed. This is
|
||||
// what UniversalPrinter<T>::Print() does when it knows nothing about
|
||||
// type T and T has neither << operator nor PrintTo().
|
||||
//
|
||||
// A user can override this behavior for a class type Foo by defining
|
||||
// a << operator in the namespace where Foo is defined.
|
||||
//
|
||||
// We put this operator in namespace 'internal2' instead of 'internal'
|
||||
// to simplify the implementation, as much code in 'internal' needs to
|
||||
// use << in STL, which would conflict with our own << were it defined
|
||||
// in 'internal'.
|
||||
//
|
||||
// Note that this operator<< takes a generic std::basic_ostream<Char,
|
||||
// CharTraits> type instead of the more restricted std::ostream. If
|
||||
// we define it to take an std::ostream instead, we'll get an
|
||||
// "ambiguous overloads" compiler error when trying to print a type
|
||||
// Foo that supports streaming to std::basic_ostream<Char,
|
||||
// CharTraits>, as the compiler cannot tell whether
|
||||
// operator<<(std::ostream&, const T&) or
|
||||
// operator<<(std::basic_stream<Char, CharTraits>, const Foo&) is more
|
||||
// specific.
|
||||
template <typename Char, typename CharTraits, typename T>
|
||||
::std::basic_ostream<Char, CharTraits>& operator<<(
|
||||
::std::basic_ostream<Char, CharTraits>& os, const T& x) {
|
||||
TypeWithoutFormatter<T, (internal::IsAProtocolMessage<T>::value
|
||||
? kProtobuf
|
||||
: std::is_convertible<
|
||||
const T&, internal::BiggestInt>::value
|
||||
? kConvertibleToInteger
|
||||
:
|
||||
#if GTEST_HAS_ABSL
|
||||
std::is_convertible<
|
||||
const T&, absl::string_view>::value
|
||||
? kConvertibleToStringView
|
||||
:
|
||||
#endif
|
||||
kOtherType)>::PrintValue(x, &os);
|
||||
return os;
|
||||
}
|
||||
|
||||
} // namespace internal2
|
||||
} // namespace testing
|
||||
|
||||
// This namespace MUST NOT BE NESTED IN ::testing, or the name look-up
|
||||
// magic needed for implementing UniversalPrinter won't work.
|
||||
namespace testing_internal {
|
||||
|
||||
// Used to print a value that is not an STL-style container when the
|
||||
// user doesn't define PrintTo() for it.
|
||||
template <typename T>
|
||||
void DefaultPrintNonContainerTo(const T& value, ::std::ostream* os) {
|
||||
// With the following statement, during unqualified name lookup,
|
||||
// testing::internal2::operator<< appears as if it was declared in
|
||||
// the nearest enclosing namespace that contains both
|
||||
// ::testing_internal and ::testing::internal2, i.e. the global
|
||||
// namespace. For more details, refer to the C++ Standard section
|
||||
// 7.3.4-1 [namespace.udir]. This allows us to fall back onto
|
||||
// testing::internal2::operator<< in case T doesn't come with a <<
|
||||
// operator.
|
||||
//
|
||||
// We cannot write 'using ::testing::internal2::operator<<;', which
|
||||
// gcc 3.3 fails to compile due to a compiler bug.
|
||||
using namespace ::testing::internal2; // NOLINT
|
||||
|
||||
// Assuming T is defined in namespace foo, in the next statement,
|
||||
// the compiler will consider all of:
|
||||
//
|
||||
// 1. foo::operator<< (thanks to Koenig look-up),
|
||||
// 2. ::operator<< (as the current namespace is enclosed in ::),
|
||||
// 3. testing::internal2::operator<< (thanks to the using statement above).
|
||||
//
|
||||
// The operator<< whose type matches T best will be picked.
|
||||
//
|
||||
// We deliberately allow #2 to be a candidate, as sometimes it's
|
||||
// impossible to define #1 (e.g. when foo is ::std, defining
|
||||
// anything in it is undefined behavior unless you are a compiler
|
||||
// vendor.).
|
||||
*os << value;
|
||||
}
|
||||
|
||||
} // namespace testing_internal
|
||||
|
||||
namespace testing {
|
||||
namespace internal {
|
||||
|
||||
// FormatForComparison<ToPrint, OtherOperand>::Format(value) formats a
|
||||
// value of type ToPrint that is an operand of a comparison assertion
|
||||
// (e.g. ASSERT_EQ). OtherOperand is the type of the other operand in
|
||||
// the comparison, and is used to help determine the best way to
|
||||
// format the value. In particular, when the value is a C string
|
||||
// (char pointer) and the other operand is an STL string object, we
|
||||
// want to format the C string as a string, since we know it is
|
||||
// compared by value with the string object. If the value is a char
|
||||
// pointer but the other operand is not an STL string object, we don't
|
||||
// know whether the pointer is supposed to point to a NUL-terminated
|
||||
// string, and thus want to print it as a pointer to be safe.
|
||||
//
|
||||
// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
|
||||
|
||||
// The default case.
|
||||
template <typename ToPrint, typename OtherOperand>
|
||||
class FormatForComparison {
|
||||
public:
|
||||
static ::std::string Format(const ToPrint& value) {
|
||||
return ::testing::PrintToString(value);
|
||||
}
|
||||
};
|
||||
|
||||
// Array.
|
||||
template <typename ToPrint, size_t N, typename OtherOperand>
|
||||
class FormatForComparison<ToPrint[N], OtherOperand> {
|
||||
public:
|
||||
static ::std::string Format(const ToPrint* value) {
|
||||
return FormatForComparison<const ToPrint*, OtherOperand>::Format(value);
|
||||
}
|
||||
};
|
||||
|
||||
// By default, print C string as pointers to be safe, as we don't know
|
||||
// whether they actually point to a NUL-terminated string.
|
||||
|
||||
#define GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(CharType) \
|
||||
template <typename OtherOperand> \
|
||||
class FormatForComparison<CharType*, OtherOperand> { \
|
||||
public: \
|
||||
static ::std::string Format(CharType* value) { \
|
||||
return ::testing::PrintToString(static_cast<const void*>(value)); \
|
||||
} \
|
||||
}
|
||||
|
||||
GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(char);
|
||||
GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(const char);
|
||||
GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(wchar_t);
|
||||
GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(const wchar_t);
|
||||
|
||||
#undef GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_
|
||||
|
||||
// If a C string is compared with an STL string object, we know it's meant
|
||||
// to point to a NUL-terminated string, and thus can print it as a string.
|
||||
|
||||
#define GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(CharType, OtherStringType) \
|
||||
template <> \
|
||||
class FormatForComparison<CharType*, OtherStringType> { \
|
||||
public: \
|
||||
static ::std::string Format(CharType* value) { \
|
||||
return ::testing::PrintToString(value); \
|
||||
} \
|
||||
}
|
||||
|
||||
GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(char, ::std::string);
|
||||
GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(const char, ::std::string);
|
||||
|
||||
#if GTEST_HAS_STD_WSTRING
|
||||
GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(wchar_t, ::std::wstring);
|
||||
GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(const wchar_t, ::std::wstring);
|
||||
#endif
|
||||
|
||||
#undef GTEST_IMPL_FORMAT_C_STRING_AS_STRING_
|
||||
|
||||
// Formats a comparison assertion (e.g. ASSERT_EQ, EXPECT_LT, and etc)
|
||||
// operand to be used in a failure message. The type (but not value)
|
||||
// of the other operand may affect the format. This allows us to
|
||||
// print a char* as a raw pointer when it is compared against another
|
||||
// char* or void*, and print it as a C string when it is compared
|
||||
// against an std::string object, for example.
|
||||
//
|
||||
// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
|
||||
template <typename T1, typename T2>
|
||||
std::string FormatForComparisonFailureMessage(
|
||||
const T1& value, const T2& /* other_operand */) {
|
||||
return FormatForComparison<T1, T2>::Format(value);
|
||||
}
|
||||
|
||||
// UniversalPrinter<T>::Print(value, ostream_ptr) prints the given
|
||||
// value to the given ostream. The caller must ensure that
|
||||
// 'ostream_ptr' is not NULL, or the behavior is undefined.
|
||||
//
|
||||
// We define UniversalPrinter as a class template (as opposed to a
|
||||
// function template), as we need to partially specialize it for
|
||||
// reference types, which cannot be done with function templates.
|
||||
template <typename T>
|
||||
class UniversalPrinter;
|
||||
|
||||
template <typename T>
|
||||
void UniversalPrint(const T& value, ::std::ostream* os);
|
||||
|
||||
enum DefaultPrinterType {
|
||||
kPrintContainer,
|
||||
kPrintPointer,
|
||||
kPrintFunctionPointer,
|
||||
kPrintOther,
|
||||
};
|
||||
template <DefaultPrinterType type> struct WrapPrinterType {};
|
||||
|
||||
// Used to print an STL-style container when the user doesn't define
|
||||
// a PrintTo() for it.
|
||||
template <typename C>
|
||||
void DefaultPrintTo(WrapPrinterType<kPrintContainer> /* dummy */,
|
||||
const C& container, ::std::ostream* os) {
|
||||
const size_t kMaxCount = 32; // The maximum number of elements to print.
|
||||
*os << '{';
|
||||
size_t count = 0;
|
||||
for (typename C::const_iterator it = container.begin();
|
||||
it != container.end(); ++it, ++count) {
|
||||
if (count > 0) {
|
||||
*os << ',';
|
||||
if (count == kMaxCount) { // Enough has been printed.
|
||||
*os << " ...";
|
||||
break;
|
||||
}
|
||||
}
|
||||
*os << ' ';
|
||||
// We cannot call PrintTo(*it, os) here as PrintTo() doesn't
|
||||
// handle *it being a native array.
|
||||
internal::UniversalPrint(*it, os);
|
||||
}
|
||||
|
||||
if (count > 0) {
|
||||
*os << ' ';
|
||||
}
|
||||
*os << '}';
|
||||
}
|
||||
|
||||
// Used to print a pointer that is neither a char pointer nor a member
|
||||
// pointer, when the user doesn't define PrintTo() for it. (A member
|
||||
// variable pointer or member function pointer doesn't really point to
|
||||
// a location in the address space. Their representation is
|
||||
// implementation-defined. Therefore they will be printed as raw
|
||||
// bytes.)
|
||||
template <typename T>
|
||||
void DefaultPrintTo(WrapPrinterType<kPrintPointer> /* dummy */,
|
||||
T* p, ::std::ostream* os) {
|
||||
if (p == nullptr) {
|
||||
*os << "NULL";
|
||||
} else {
|
||||
// T is not a function type. We just call << to print p,
|
||||
// relying on ADL to pick up user-defined << for their pointer
|
||||
// types, if any.
|
||||
*os << p;
|
||||
}
|
||||
}
|
||||
template <typename T>
|
||||
void DefaultPrintTo(WrapPrinterType<kPrintFunctionPointer> /* dummy */,
|
||||
T* p, ::std::ostream* os) {
|
||||
if (p == nullptr) {
|
||||
*os << "NULL";
|
||||
} else {
|
||||
// T is a function type, so '*os << p' doesn't do what we want
|
||||
// (it just prints p as bool). We want to print p as a const
|
||||
// void*.
|
||||
*os << reinterpret_cast<const void*>(p);
|
||||
}
|
||||
}
|
||||
|
||||
// Used to print a non-container, non-pointer value when the user
|
||||
// doesn't define PrintTo() for it.
|
||||
template <typename T>
|
||||
void DefaultPrintTo(WrapPrinterType<kPrintOther> /* dummy */,
|
||||
const T& value, ::std::ostream* os) {
|
||||
::testing_internal::DefaultPrintNonContainerTo(value, os);
|
||||
}
|
||||
|
||||
// Prints the given value using the << operator if it has one;
|
||||
// otherwise prints the bytes in it. This is what
|
||||
// UniversalPrinter<T>::Print() does when PrintTo() is not specialized
|
||||
// or overloaded for type T.
|
||||
//
|
||||
// A user can override this behavior for a class type Foo by defining
|
||||
// an overload of PrintTo() in the namespace where Foo is defined. We
|
||||
// give the user this option as sometimes defining a << operator for
|
||||
// Foo is not desirable (e.g. the coding style may prevent doing it,
|
||||
// or there is already a << operator but it doesn't do what the user
|
||||
// wants).
|
||||
template <typename T>
|
||||
void PrintTo(const T& value, ::std::ostream* os) {
|
||||
// DefaultPrintTo() is overloaded. The type of its first argument
|
||||
// determines which version will be picked.
|
||||
//
|
||||
// Note that we check for container types here, prior to we check
|
||||
// for protocol message types in our operator<<. The rationale is:
|
||||
//
|
||||
// For protocol messages, we want to give people a chance to
|
||||
// override Google Mock's format by defining a PrintTo() or
|
||||
// operator<<. For STL containers, other formats can be
|
||||
// incompatible with Google Mock's format for the container
|
||||
// elements; therefore we check for container types here to ensure
|
||||
// that our format is used.
|
||||
//
|
||||
// Note that MSVC and clang-cl do allow an implicit conversion from
|
||||
// pointer-to-function to pointer-to-object, but clang-cl warns on it.
|
||||
// So don't use ImplicitlyConvertible if it can be helped since it will
|
||||
// cause this warning, and use a separate overload of DefaultPrintTo for
|
||||
// function pointers so that the `*os << p` in the object pointer overload
|
||||
// doesn't cause that warning either.
|
||||
DefaultPrintTo(
|
||||
WrapPrinterType <
|
||||
(sizeof(IsContainerTest<T>(0)) == sizeof(IsContainer)) &&
|
||||
!IsRecursiveContainer<T>::value
|
||||
? kPrintContainer
|
||||
: !std::is_pointer<T>::value
|
||||
? kPrintOther
|
||||
: std::is_function<typename std::remove_pointer<T>::type>::value
|
||||
? kPrintFunctionPointer
|
||||
: kPrintPointer > (),
|
||||
value, os);
|
||||
}
|
||||
|
||||
// The following list of PrintTo() overloads tells
|
||||
// UniversalPrinter<T>::Print() how to print standard types (built-in
|
||||
// types, strings, plain arrays, and pointers).
|
||||
|
||||
// Overloads for various char types.
|
||||
GTEST_API_ void PrintTo(unsigned char c, ::std::ostream* os);
|
||||
GTEST_API_ void PrintTo(signed char c, ::std::ostream* os);
|
||||
inline void PrintTo(char c, ::std::ostream* os) {
|
||||
// When printing a plain char, we always treat it as unsigned. This
|
||||
// way, the output won't be affected by whether the compiler thinks
|
||||
// char is signed or not.
|
||||
PrintTo(static_cast<unsigned char>(c), os);
|
||||
}
|
||||
|
||||
// Overloads for other simple built-in types.
|
||||
inline void PrintTo(bool x, ::std::ostream* os) {
|
||||
*os << (x ? "true" : "false");
|
||||
}
|
||||
|
||||
// Overload for wchar_t type.
|
||||
// Prints a wchar_t as a symbol if it is printable or as its internal
|
||||
// code otherwise and also as its decimal code (except for L'\0').
|
||||
// The L'\0' char is printed as "L'\\0'". The decimal code is printed
|
||||
// as signed integer when wchar_t is implemented by the compiler
|
||||
// as a signed type and is printed as an unsigned integer when wchar_t
|
||||
// is implemented as an unsigned type.
|
||||
GTEST_API_ void PrintTo(wchar_t wc, ::std::ostream* os);
|
||||
|
||||
// Overloads for C strings.
|
||||
GTEST_API_ void PrintTo(const char* s, ::std::ostream* os);
|
||||
inline void PrintTo(char* s, ::std::ostream* os) {
|
||||
PrintTo(ImplicitCast_<const char*>(s), os);
|
||||
}
|
||||
|
||||
// signed/unsigned char is often used for representing binary data, so
|
||||
// we print pointers to it as void* to be safe.
|
||||
inline void PrintTo(const signed char* s, ::std::ostream* os) {
|
||||
PrintTo(ImplicitCast_<const void*>(s), os);
|
||||
}
|
||||
inline void PrintTo(signed char* s, ::std::ostream* os) {
|
||||
PrintTo(ImplicitCast_<const void*>(s), os);
|
||||
}
|
||||
inline void PrintTo(const unsigned char* s, ::std::ostream* os) {
|
||||
PrintTo(ImplicitCast_<const void*>(s), os);
|
||||
}
|
||||
inline void PrintTo(unsigned char* s, ::std::ostream* os) {
|
||||
PrintTo(ImplicitCast_<const void*>(s), os);
|
||||
}
|
||||
|
||||
// MSVC can be configured to define wchar_t as a typedef of unsigned
|
||||
// short. It defines _NATIVE_WCHAR_T_DEFINED when wchar_t is a native
|
||||
// type. When wchar_t is a typedef, defining an overload for const
|
||||
// wchar_t* would cause unsigned short* be printed as a wide string,
|
||||
// possibly causing invalid memory accesses.
|
||||
#if !defined(_MSC_VER) || defined(_NATIVE_WCHAR_T_DEFINED)
|
||||
// Overloads for wide C strings
|
||||
GTEST_API_ void PrintTo(const wchar_t* s, ::std::ostream* os);
|
||||
inline void PrintTo(wchar_t* s, ::std::ostream* os) {
|
||||
PrintTo(ImplicitCast_<const wchar_t*>(s), os);
|
||||
}
|
||||
#endif
|
||||
|
||||
// Overload for C arrays. Multi-dimensional arrays are printed
|
||||
// properly.
|
||||
|
||||
// Prints the given number of elements in an array, without printing
|
||||
// the curly braces.
|
||||
template <typename T>
|
||||
void PrintRawArrayTo(const T a[], size_t count, ::std::ostream* os) {
|
||||
UniversalPrint(a[0], os);
|
||||
for (size_t i = 1; i != count; i++) {
|
||||
*os << ", ";
|
||||
UniversalPrint(a[i], os);
|
||||
}
|
||||
}
|
||||
|
||||
// Overloads for ::std::string.
|
||||
GTEST_API_ void PrintStringTo(const ::std::string&s, ::std::ostream* os);
|
||||
inline void PrintTo(const ::std::string& s, ::std::ostream* os) {
|
||||
PrintStringTo(s, os);
|
||||
}
|
||||
|
||||
// Overloads for ::std::wstring.
|
||||
#if GTEST_HAS_STD_WSTRING
|
||||
GTEST_API_ void PrintWideStringTo(const ::std::wstring&s, ::std::ostream* os);
|
||||
inline void PrintTo(const ::std::wstring& s, ::std::ostream* os) {
|
||||
PrintWideStringTo(s, os);
|
||||
}
|
||||
#endif // GTEST_HAS_STD_WSTRING
|
||||
|
||||
#if GTEST_HAS_ABSL
|
||||
// Overload for absl::string_view.
|
||||
inline void PrintTo(absl::string_view sp, ::std::ostream* os) {
|
||||
PrintTo(::std::string(sp), os);
|
||||
}
|
||||
#endif // GTEST_HAS_ABSL
|
||||
|
||||
inline void PrintTo(std::nullptr_t, ::std::ostream* os) { *os << "(nullptr)"; }
|
||||
|
||||
template <typename T>
|
||||
void PrintTo(std::reference_wrapper<T> ref, ::std::ostream* os) {
|
||||
UniversalPrinter<T&>::Print(ref.get(), os);
|
||||
}
|
||||
|
||||
// Helper function for printing a tuple. T must be instantiated with
|
||||
// a tuple type.
|
||||
template <typename T>
|
||||
void PrintTupleTo(const T&, std::integral_constant<size_t, 0>,
|
||||
::std::ostream*) {}
|
||||
|
||||
template <typename T, size_t I>
|
||||
void PrintTupleTo(const T& t, std::integral_constant<size_t, I>,
|
||||
::std::ostream* os) {
|
||||
PrintTupleTo(t, std::integral_constant<size_t, I - 1>(), os);
|
||||
GTEST_INTENTIONAL_CONST_COND_PUSH_()
|
||||
if (I > 1) {
|
||||
GTEST_INTENTIONAL_CONST_COND_POP_()
|
||||
*os << ", ";
|
||||
}
|
||||
UniversalPrinter<typename std::tuple_element<I - 1, T>::type>::Print(
|
||||
std::get<I - 1>(t), os);
|
||||
}
|
||||
|
||||
template <typename... Types>
|
||||
void PrintTo(const ::std::tuple<Types...>& t, ::std::ostream* os) {
|
||||
*os << "(";
|
||||
PrintTupleTo(t, std::integral_constant<size_t, sizeof...(Types)>(), os);
|
||||
*os << ")";
|
||||
}
|
||||
|
||||
// Overload for std::pair.
|
||||
template <typename T1, typename T2>
|
||||
void PrintTo(const ::std::pair<T1, T2>& value, ::std::ostream* os) {
|
||||
*os << '(';
|
||||
// We cannot use UniversalPrint(value.first, os) here, as T1 may be
|
||||
// a reference type. The same for printing value.second.
|
||||
UniversalPrinter<T1>::Print(value.first, os);
|
||||
*os << ", ";
|
||||
UniversalPrinter<T2>::Print(value.second, os);
|
||||
*os << ')';
|
||||
}
|
||||
|
||||
// Implements printing a non-reference type T by letting the compiler
|
||||
// pick the right overload of PrintTo() for T.
|
||||
template <typename T>
|
||||
class UniversalPrinter {
|
||||
public:
|
||||
// MSVC warns about adding const to a function type, so we want to
|
||||
// disable the warning.
|
||||
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4180)
|
||||
|
||||
// Note: we deliberately don't call this PrintTo(), as that name
|
||||
// conflicts with ::testing::internal::PrintTo in the body of the
|
||||
// function.
|
||||
static void Print(const T& value, ::std::ostream* os) {
|
||||
// By default, ::testing::internal::PrintTo() is used for printing
|
||||
// the value.
|
||||
//
|
||||
// Thanks to Koenig look-up, if T is a class and has its own
|
||||
// PrintTo() function defined in its namespace, that function will
|
||||
// be visible here. Since it is more specific than the generic ones
|
||||
// in ::testing::internal, it will be picked by the compiler in the
|
||||
// following statement - exactly what we want.
|
||||
PrintTo(value, os);
|
||||
}
|
||||
|
||||
GTEST_DISABLE_MSC_WARNINGS_POP_()
|
||||
};
|
||||
|
||||
#if GTEST_HAS_ABSL
|
||||
|
||||
// Printer for absl::optional
|
||||
|
||||
template <typename T>
|
||||
class UniversalPrinter<::absl::optional<T>> {
|
||||
public:
|
||||
static void Print(const ::absl::optional<T>& value, ::std::ostream* os) {
|
||||
*os << '(';
|
||||
if (!value) {
|
||||
*os << "nullopt";
|
||||
} else {
|
||||
UniversalPrint(*value, os);
|
||||
}
|
||||
*os << ')';
|
||||
}
|
||||
};
|
||||
|
||||
// Printer for absl::variant
|
||||
|
||||
template <typename... T>
|
||||
class UniversalPrinter<::absl::variant<T...>> {
|
||||
public:
|
||||
static void Print(const ::absl::variant<T...>& value, ::std::ostream* os) {
|
||||
*os << '(';
|
||||
absl::visit(Visitor{os}, value);
|
||||
*os << ')';
|
||||
}
|
||||
|
||||
private:
|
||||
struct Visitor {
|
||||
template <typename U>
|
||||
void operator()(const U& u) const {
|
||||
*os << "'" << GetTypeName<U>() << "' with value ";
|
||||
UniversalPrint(u, os);
|
||||
}
|
||||
::std::ostream* os;
|
||||
};
|
||||
};
|
||||
|
||||
#endif // GTEST_HAS_ABSL
|
||||
|
||||
// UniversalPrintArray(begin, len, os) prints an array of 'len'
|
||||
// elements, starting at address 'begin'.
|
||||
template <typename T>
|
||||
void UniversalPrintArray(const T* begin, size_t len, ::std::ostream* os) {
|
||||
if (len == 0) {
|
||||
*os << "{}";
|
||||
} else {
|
||||
*os << "{ ";
|
||||
const size_t kThreshold = 18;
|
||||
const size_t kChunkSize = 8;
|
||||
// If the array has more than kThreshold elements, we'll have to
|
||||
// omit some details by printing only the first and the last
|
||||
// kChunkSize elements.
|
||||
if (len <= kThreshold) {
|
||||
PrintRawArrayTo(begin, len, os);
|
||||
} else {
|
||||
PrintRawArrayTo(begin, kChunkSize, os);
|
||||
*os << ", ..., ";
|
||||
PrintRawArrayTo(begin + len - kChunkSize, kChunkSize, os);
|
||||
}
|
||||
*os << " }";
|
||||
}
|
||||
}
|
||||
// This overload prints a (const) char array compactly.
|
||||
GTEST_API_ void UniversalPrintArray(
|
||||
const char* begin, size_t len, ::std::ostream* os);
|
||||
|
||||
// This overload prints a (const) wchar_t array compactly.
|
||||
GTEST_API_ void UniversalPrintArray(
|
||||
const wchar_t* begin, size_t len, ::std::ostream* os);
|
||||
|
||||
// Implements printing an array type T[N].
|
||||
template <typename T, size_t N>
|
||||
class UniversalPrinter<T[N]> {
|
||||
public:
|
||||
// Prints the given array, omitting some elements when there are too
|
||||
// many.
|
||||
static void Print(const T (&a)[N], ::std::ostream* os) {
|
||||
UniversalPrintArray(a, N, os);
|
||||
}
|
||||
};
|
||||
|
||||
// Implements printing a reference type T&.
|
||||
template <typename T>
|
||||
class UniversalPrinter<T&> {
|
||||
public:
|
||||
// MSVC warns about adding const to a function type, so we want to
|
||||
// disable the warning.
|
||||
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4180)
|
||||
|
||||
static void Print(const T& value, ::std::ostream* os) {
|
||||
// Prints the address of the value. We use reinterpret_cast here
|
||||
// as static_cast doesn't compile when T is a function type.
|
||||
*os << "@" << reinterpret_cast<const void*>(&value) << " ";
|
||||
|
||||
// Then prints the value itself.
|
||||
UniversalPrint(value, os);
|
||||
}
|
||||
|
||||
GTEST_DISABLE_MSC_WARNINGS_POP_()
|
||||
};
|
||||
|
||||
// Prints a value tersely: for a reference type, the referenced value
|
||||
// (but not the address) is printed; for a (const) char pointer, the
|
||||
// NUL-terminated string (but not the pointer) is printed.
|
||||
|
||||
template <typename T>
|
||||
class UniversalTersePrinter {
|
||||
public:
|
||||
static void Print(const T& value, ::std::ostream* os) {
|
||||
UniversalPrint(value, os);
|
||||
}
|
||||
};
|
||||
template <typename T>
|
||||
class UniversalTersePrinter<T&> {
|
||||
public:
|
||||
static void Print(const T& value, ::std::ostream* os) {
|
||||
UniversalPrint(value, os);
|
||||
}
|
||||
};
|
||||
template <typename T, size_t N>
|
||||
class UniversalTersePrinter<T[N]> {
|
||||
public:
|
||||
static void Print(const T (&value)[N], ::std::ostream* os) {
|
||||
UniversalPrinter<T[N]>::Print(value, os);
|
||||
}
|
||||
};
|
||||
template <>
|
||||
class UniversalTersePrinter<const char*> {
|
||||
public:
|
||||
static void Print(const char* str, ::std::ostream* os) {
|
||||
if (str == nullptr) {
|
||||
*os << "NULL";
|
||||
} else {
|
||||
UniversalPrint(std::string(str), os);
|
||||
}
|
||||
}
|
||||
};
|
||||
template <>
|
||||
class UniversalTersePrinter<char*> {
|
||||
public:
|
||||
static void Print(char* str, ::std::ostream* os) {
|
||||
UniversalTersePrinter<const char*>::Print(str, os);
|
||||
}
|
||||
};
|
||||
|
||||
#if GTEST_HAS_STD_WSTRING
|
||||
template <>
|
||||
class UniversalTersePrinter<const wchar_t*> {
|
||||
public:
|
||||
static void Print(const wchar_t* str, ::std::ostream* os) {
|
||||
if (str == nullptr) {
|
||||
*os << "NULL";
|
||||
} else {
|
||||
UniversalPrint(::std::wstring(str), os);
|
||||
}
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
||||
template <>
|
||||
class UniversalTersePrinter<wchar_t*> {
|
||||
public:
|
||||
static void Print(wchar_t* str, ::std::ostream* os) {
|
||||
UniversalTersePrinter<const wchar_t*>::Print(str, os);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
void UniversalTersePrint(const T& value, ::std::ostream* os) {
|
||||
UniversalTersePrinter<T>::Print(value, os);
|
||||
}
|
||||
|
||||
// Prints a value using the type inferred by the compiler. The
|
||||
// difference between this and UniversalTersePrint() is that for a
|
||||
// (const) char pointer, this prints both the pointer and the
|
||||
// NUL-terminated string.
|
||||
template <typename T>
|
||||
void UniversalPrint(const T& value, ::std::ostream* os) {
|
||||
// A workarond for the bug in VC++ 7.1 that prevents us from instantiating
|
||||
// UniversalPrinter with T directly.
|
||||
typedef T T1;
|
||||
UniversalPrinter<T1>::Print(value, os);
|
||||
}
|
||||
|
||||
typedef ::std::vector< ::std::string> Strings;
|
||||
|
||||
// Tersely prints the first N fields of a tuple to a string vector,
|
||||
// one element for each field.
|
||||
template <typename Tuple>
|
||||
void TersePrintPrefixToStrings(const Tuple&, std::integral_constant<size_t, 0>,
|
||||
Strings*) {}
|
||||
template <typename Tuple, size_t I>
|
||||
void TersePrintPrefixToStrings(const Tuple& t,
|
||||
std::integral_constant<size_t, I>,
|
||||
Strings* strings) {
|
||||
TersePrintPrefixToStrings(t, std::integral_constant<size_t, I - 1>(),
|
||||
strings);
|
||||
::std::stringstream ss;
|
||||
UniversalTersePrint(std::get<I - 1>(t), &ss);
|
||||
strings->push_back(ss.str());
|
||||
}
|
||||
|
||||
// Prints the fields of a tuple tersely to a string vector, one
|
||||
// element for each field. See the comment before
|
||||
// UniversalTersePrint() for how we define "tersely".
|
||||
template <typename Tuple>
|
||||
Strings UniversalTersePrintTupleFieldsToStrings(const Tuple& value) {
|
||||
Strings result;
|
||||
TersePrintPrefixToStrings(
|
||||
value, std::integral_constant<size_t, std::tuple_size<Tuple>::value>(),
|
||||
&result);
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace internal
|
||||
|
||||
#if GTEST_HAS_ABSL
|
||||
namespace internal2 {
|
||||
template <typename T>
|
||||
void TypeWithoutFormatter<T, kConvertibleToStringView>::PrintValue(
|
||||
const T& value, ::std::ostream* os) {
|
||||
internal::PrintTo(absl::string_view(value), os);
|
||||
}
|
||||
} // namespace internal2
|
||||
#endif
|
||||
|
||||
template <typename T>
|
||||
::std::string PrintToString(const T& value) {
|
||||
::std::stringstream ss;
|
||||
internal::UniversalTersePrinter<T>::Print(value, &ss);
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
} // namespace testing
|
||||
|
||||
// Include any custom printer added by the local installation.
|
||||
// We must include this header at the end to make sure it can use the
|
||||
// declarations from this file.
|
||||
#include "gtest/internal/custom/gtest-printers.h"
|
||||
|
||||
#endif // GTEST_INCLUDE_GTEST_GTEST_PRINTERS_H_
|
||||
@@ -1,238 +0,0 @@
|
||||
// Copyright 2007, Google Inc.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
//
|
||||
// Utilities for testing Google Test itself and code that uses Google Test
|
||||
// (e.g. frameworks built on top of Google Test).
|
||||
|
||||
// GOOGLETEST_CM0004 DO NOT DELETE
|
||||
|
||||
#ifndef GTEST_INCLUDE_GTEST_GTEST_SPI_H_
|
||||
#define GTEST_INCLUDE_GTEST_GTEST_SPI_H_
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251 \
|
||||
/* class A needs to have dll-interface to be used by clients of class B */)
|
||||
|
||||
namespace testing {
|
||||
|
||||
// This helper class can be used to mock out Google Test failure reporting
|
||||
// so that we can test Google Test or code that builds on Google Test.
|
||||
//
|
||||
// An object of this class appends a TestPartResult object to the
|
||||
// TestPartResultArray object given in the constructor whenever a Google Test
|
||||
// failure is reported. It can either intercept only failures that are
|
||||
// generated in the same thread that created this object or it can intercept
|
||||
// all generated failures. The scope of this mock object can be controlled with
|
||||
// the second argument to the two arguments constructor.
|
||||
class GTEST_API_ ScopedFakeTestPartResultReporter
|
||||
: public TestPartResultReporterInterface {
|
||||
public:
|
||||
// The two possible mocking modes of this object.
|
||||
enum InterceptMode {
|
||||
INTERCEPT_ONLY_CURRENT_THREAD, // Intercepts only thread local failures.
|
||||
INTERCEPT_ALL_THREADS // Intercepts all failures.
|
||||
};
|
||||
|
||||
// The c'tor sets this object as the test part result reporter used
|
||||
// by Google Test. The 'result' parameter specifies where to report the
|
||||
// results. This reporter will only catch failures generated in the current
|
||||
// thread. DEPRECATED
|
||||
explicit ScopedFakeTestPartResultReporter(TestPartResultArray* result);
|
||||
|
||||
// Same as above, but you can choose the interception scope of this object.
|
||||
ScopedFakeTestPartResultReporter(InterceptMode intercept_mode,
|
||||
TestPartResultArray* result);
|
||||
|
||||
// The d'tor restores the previous test part result reporter.
|
||||
~ScopedFakeTestPartResultReporter() override;
|
||||
|
||||
// Appends the TestPartResult object to the TestPartResultArray
|
||||
// received in the constructor.
|
||||
//
|
||||
// This method is from the TestPartResultReporterInterface
|
||||
// interface.
|
||||
void ReportTestPartResult(const TestPartResult& result) override;
|
||||
|
||||
private:
|
||||
void Init();
|
||||
|
||||
const InterceptMode intercept_mode_;
|
||||
TestPartResultReporterInterface* old_reporter_;
|
||||
TestPartResultArray* const result_;
|
||||
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(ScopedFakeTestPartResultReporter);
|
||||
};
|
||||
|
||||
namespace internal {
|
||||
|
||||
// A helper class for implementing EXPECT_FATAL_FAILURE() and
|
||||
// EXPECT_NONFATAL_FAILURE(). Its destructor verifies that the given
|
||||
// TestPartResultArray contains exactly one failure that has the given
|
||||
// type and contains the given substring. If that's not the case, a
|
||||
// non-fatal failure will be generated.
|
||||
class GTEST_API_ SingleFailureChecker {
|
||||
public:
|
||||
// The constructor remembers the arguments.
|
||||
SingleFailureChecker(const TestPartResultArray* results,
|
||||
TestPartResult::Type type, const std::string& substr);
|
||||
~SingleFailureChecker();
|
||||
private:
|
||||
const TestPartResultArray* const results_;
|
||||
const TestPartResult::Type type_;
|
||||
const std::string substr_;
|
||||
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(SingleFailureChecker);
|
||||
};
|
||||
|
||||
} // namespace internal
|
||||
|
||||
} // namespace testing
|
||||
|
||||
GTEST_DISABLE_MSC_WARNINGS_POP_() // 4251
|
||||
|
||||
// A set of macros for testing Google Test assertions or code that's expected
|
||||
// to generate Google Test fatal failures. It verifies that the given
|
||||
// statement will cause exactly one fatal Google Test failure with 'substr'
|
||||
// being part of the failure message.
|
||||
//
|
||||
// There are two different versions of this macro. EXPECT_FATAL_FAILURE only
|
||||
// affects and considers failures generated in the current thread and
|
||||
// EXPECT_FATAL_FAILURE_ON_ALL_THREADS does the same but for all threads.
|
||||
//
|
||||
// The verification of the assertion is done correctly even when the statement
|
||||
// throws an exception or aborts the current function.
|
||||
//
|
||||
// Known restrictions:
|
||||
// - 'statement' cannot reference local non-static variables or
|
||||
// non-static members of the current object.
|
||||
// - 'statement' cannot return a value.
|
||||
// - You cannot stream a failure message to this macro.
|
||||
//
|
||||
// Note that even though the implementations of the following two
|
||||
// macros are much alike, we cannot refactor them to use a common
|
||||
// helper macro, due to some peculiarity in how the preprocessor
|
||||
// works. The AcceptsMacroThatExpandsToUnprotectedComma test in
|
||||
// gtest_unittest.cc will fail to compile if we do that.
|
||||
#define EXPECT_FATAL_FAILURE(statement, substr) \
|
||||
do { \
|
||||
class GTestExpectFatalFailureHelper {\
|
||||
public:\
|
||||
static void Execute() { statement; }\
|
||||
};\
|
||||
::testing::TestPartResultArray gtest_failures;\
|
||||
::testing::internal::SingleFailureChecker gtest_checker(\
|
||||
>est_failures, ::testing::TestPartResult::kFatalFailure, (substr));\
|
||||
{\
|
||||
::testing::ScopedFakeTestPartResultReporter gtest_reporter(\
|
||||
::testing::ScopedFakeTestPartResultReporter:: \
|
||||
INTERCEPT_ONLY_CURRENT_THREAD, >est_failures);\
|
||||
GTestExpectFatalFailureHelper::Execute();\
|
||||
}\
|
||||
} while (::testing::internal::AlwaysFalse())
|
||||
|
||||
#define EXPECT_FATAL_FAILURE_ON_ALL_THREADS(statement, substr) \
|
||||
do { \
|
||||
class GTestExpectFatalFailureHelper {\
|
||||
public:\
|
||||
static void Execute() { statement; }\
|
||||
};\
|
||||
::testing::TestPartResultArray gtest_failures;\
|
||||
::testing::internal::SingleFailureChecker gtest_checker(\
|
||||
>est_failures, ::testing::TestPartResult::kFatalFailure, (substr));\
|
||||
{\
|
||||
::testing::ScopedFakeTestPartResultReporter gtest_reporter(\
|
||||
::testing::ScopedFakeTestPartResultReporter:: \
|
||||
INTERCEPT_ALL_THREADS, >est_failures);\
|
||||
GTestExpectFatalFailureHelper::Execute();\
|
||||
}\
|
||||
} while (::testing::internal::AlwaysFalse())
|
||||
|
||||
// A macro for testing Google Test assertions or code that's expected to
|
||||
// generate Google Test non-fatal failures. It asserts that the given
|
||||
// statement will cause exactly one non-fatal Google Test failure with 'substr'
|
||||
// being part of the failure message.
|
||||
//
|
||||
// There are two different versions of this macro. EXPECT_NONFATAL_FAILURE only
|
||||
// affects and considers failures generated in the current thread and
|
||||
// EXPECT_NONFATAL_FAILURE_ON_ALL_THREADS does the same but for all threads.
|
||||
//
|
||||
// 'statement' is allowed to reference local variables and members of
|
||||
// the current object.
|
||||
//
|
||||
// The verification of the assertion is done correctly even when the statement
|
||||
// throws an exception or aborts the current function.
|
||||
//
|
||||
// Known restrictions:
|
||||
// - You cannot stream a failure message to this macro.
|
||||
//
|
||||
// Note that even though the implementations of the following two
|
||||
// macros are much alike, we cannot refactor them to use a common
|
||||
// helper macro, due to some peculiarity in how the preprocessor
|
||||
// works. If we do that, the code won't compile when the user gives
|
||||
// EXPECT_NONFATAL_FAILURE() a statement that contains a macro that
|
||||
// expands to code containing an unprotected comma. The
|
||||
// AcceptsMacroThatExpandsToUnprotectedComma test in gtest_unittest.cc
|
||||
// catches that.
|
||||
//
|
||||
// For the same reason, we have to write
|
||||
// if (::testing::internal::AlwaysTrue()) { statement; }
|
||||
// instead of
|
||||
// GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement)
|
||||
// to avoid an MSVC warning on unreachable code.
|
||||
#define EXPECT_NONFATAL_FAILURE(statement, substr) \
|
||||
do {\
|
||||
::testing::TestPartResultArray gtest_failures;\
|
||||
::testing::internal::SingleFailureChecker gtest_checker(\
|
||||
>est_failures, ::testing::TestPartResult::kNonFatalFailure, \
|
||||
(substr));\
|
||||
{\
|
||||
::testing::ScopedFakeTestPartResultReporter gtest_reporter(\
|
||||
::testing::ScopedFakeTestPartResultReporter:: \
|
||||
INTERCEPT_ONLY_CURRENT_THREAD, >est_failures);\
|
||||
if (::testing::internal::AlwaysTrue()) { statement; }\
|
||||
}\
|
||||
} while (::testing::internal::AlwaysFalse())
|
||||
|
||||
#define EXPECT_NONFATAL_FAILURE_ON_ALL_THREADS(statement, substr) \
|
||||
do {\
|
||||
::testing::TestPartResultArray gtest_failures;\
|
||||
::testing::internal::SingleFailureChecker gtest_checker(\
|
||||
>est_failures, ::testing::TestPartResult::kNonFatalFailure, \
|
||||
(substr));\
|
||||
{\
|
||||
::testing::ScopedFakeTestPartResultReporter gtest_reporter(\
|
||||
::testing::ScopedFakeTestPartResultReporter::INTERCEPT_ALL_THREADS, \
|
||||
>est_failures);\
|
||||
if (::testing::internal::AlwaysTrue()) { statement; }\
|
||||
}\
|
||||
} while (::testing::internal::AlwaysFalse())
|
||||
|
||||
#endif // GTEST_INCLUDE_GTEST_GTEST_SPI_H_
|
||||
@@ -1,184 +0,0 @@
|
||||
// Copyright 2008, Google Inc.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// GOOGLETEST_CM0001 DO NOT DELETE
|
||||
|
||||
#ifndef GTEST_INCLUDE_GTEST_GTEST_TEST_PART_H_
|
||||
#define GTEST_INCLUDE_GTEST_GTEST_TEST_PART_H_
|
||||
|
||||
#include <iosfwd>
|
||||
#include <vector>
|
||||
#include "gtest/internal/gtest-internal.h"
|
||||
#include "gtest/internal/gtest-string.h"
|
||||
|
||||
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251 \
|
||||
/* class A needs to have dll-interface to be used by clients of class B */)
|
||||
|
||||
namespace testing {
|
||||
|
||||
// A copyable object representing the result of a test part (i.e. an
|
||||
// assertion or an explicit FAIL(), ADD_FAILURE(), or SUCCESS()).
|
||||
//
|
||||
// Don't inherit from TestPartResult as its destructor is not virtual.
|
||||
class GTEST_API_ TestPartResult {
|
||||
public:
|
||||
// The possible outcomes of a test part (i.e. an assertion or an
|
||||
// explicit SUCCEED(), FAIL(), or ADD_FAILURE()).
|
||||
enum Type {
|
||||
kSuccess, // Succeeded.
|
||||
kNonFatalFailure, // Failed but the test can continue.
|
||||
kFatalFailure, // Failed and the test should be terminated.
|
||||
kSkip // Skipped.
|
||||
};
|
||||
|
||||
// C'tor. TestPartResult does NOT have a default constructor.
|
||||
// Always use this constructor (with parameters) to create a
|
||||
// TestPartResult object.
|
||||
TestPartResult(Type a_type, const char* a_file_name, int a_line_number,
|
||||
const char* a_message)
|
||||
: type_(a_type),
|
||||
file_name_(a_file_name == nullptr ? "" : a_file_name),
|
||||
line_number_(a_line_number),
|
||||
summary_(ExtractSummary(a_message)),
|
||||
message_(a_message) {}
|
||||
|
||||
// Gets the outcome of the test part.
|
||||
Type type() const { return type_; }
|
||||
|
||||
// Gets the name of the source file where the test part took place, or
|
||||
// NULL if it's unknown.
|
||||
const char* file_name() const {
|
||||
return file_name_.empty() ? nullptr : file_name_.c_str();
|
||||
}
|
||||
|
||||
// Gets the line in the source file where the test part took place,
|
||||
// or -1 if it's unknown.
|
||||
int line_number() const { return line_number_; }
|
||||
|
||||
// Gets the summary of the failure message.
|
||||
const char* summary() const { return summary_.c_str(); }
|
||||
|
||||
// Gets the message associated with the test part.
|
||||
const char* message() const { return message_.c_str(); }
|
||||
|
||||
// Returns true if and only if the test part was skipped.
|
||||
bool skipped() const { return type_ == kSkip; }
|
||||
|
||||
// Returns true if and only if the test part passed.
|
||||
bool passed() const { return type_ == kSuccess; }
|
||||
|
||||
// Returns true if and only if the test part non-fatally failed.
|
||||
bool nonfatally_failed() const { return type_ == kNonFatalFailure; }
|
||||
|
||||
// Returns true if and only if the test part fatally failed.
|
||||
bool fatally_failed() const { return type_ == kFatalFailure; }
|
||||
|
||||
// Returns true if and only if the test part failed.
|
||||
bool failed() const { return fatally_failed() || nonfatally_failed(); }
|
||||
|
||||
private:
|
||||
Type type_;
|
||||
|
||||
// Gets the summary of the failure message by omitting the stack
|
||||
// trace in it.
|
||||
static std::string ExtractSummary(const char* message);
|
||||
|
||||
// The name of the source file where the test part took place, or
|
||||
// "" if the source file is unknown.
|
||||
std::string file_name_;
|
||||
// The line in the source file where the test part took place, or -1
|
||||
// if the line number is unknown.
|
||||
int line_number_;
|
||||
std::string summary_; // The test failure summary.
|
||||
std::string message_; // The test failure message.
|
||||
};
|
||||
|
||||
// Prints a TestPartResult object.
|
||||
std::ostream& operator<<(std::ostream& os, const TestPartResult& result);
|
||||
|
||||
// An array of TestPartResult objects.
|
||||
//
|
||||
// Don't inherit from TestPartResultArray as its destructor is not
|
||||
// virtual.
|
||||
class GTEST_API_ TestPartResultArray {
|
||||
public:
|
||||
TestPartResultArray() {}
|
||||
|
||||
// Appends the given TestPartResult to the array.
|
||||
void Append(const TestPartResult& result);
|
||||
|
||||
// Returns the TestPartResult at the given index (0-based).
|
||||
const TestPartResult& GetTestPartResult(int index) const;
|
||||
|
||||
// Returns the number of TestPartResult objects in the array.
|
||||
int size() const;
|
||||
|
||||
private:
|
||||
std::vector<TestPartResult> array_;
|
||||
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(TestPartResultArray);
|
||||
};
|
||||
|
||||
// This interface knows how to report a test part result.
|
||||
class GTEST_API_ TestPartResultReporterInterface {
|
||||
public:
|
||||
virtual ~TestPartResultReporterInterface() {}
|
||||
|
||||
virtual void ReportTestPartResult(const TestPartResult& result) = 0;
|
||||
};
|
||||
|
||||
namespace internal {
|
||||
|
||||
// This helper class is used by {ASSERT|EXPECT}_NO_FATAL_FAILURE to check if a
|
||||
// statement generates new fatal failures. To do so it registers itself as the
|
||||
// current test part result reporter. Besides checking if fatal failures were
|
||||
// reported, it only delegates the reporting to the former result reporter.
|
||||
// The original result reporter is restored in the destructor.
|
||||
// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
|
||||
class GTEST_API_ HasNewFatalFailureHelper
|
||||
: public TestPartResultReporterInterface {
|
||||
public:
|
||||
HasNewFatalFailureHelper();
|
||||
~HasNewFatalFailureHelper() override;
|
||||
void ReportTestPartResult(const TestPartResult& result) override;
|
||||
bool has_new_fatal_failure() const { return has_new_fatal_failure_; }
|
||||
private:
|
||||
bool has_new_fatal_failure_;
|
||||
TestPartResultReporterInterface* original_reporter_;
|
||||
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(HasNewFatalFailureHelper);
|
||||
};
|
||||
|
||||
} // namespace internal
|
||||
|
||||
} // namespace testing
|
||||
|
||||
GTEST_DISABLE_MSC_WARNINGS_POP_() // 4251
|
||||
|
||||
#endif // GTEST_INCLUDE_GTEST_GTEST_TEST_PART_H_
|
||||
@@ -1,330 +0,0 @@
|
||||
// Copyright 2008 Google Inc.
|
||||
// All Rights Reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
|
||||
// GOOGLETEST_CM0001 DO NOT DELETE
|
||||
|
||||
#ifndef GTEST_INCLUDE_GTEST_GTEST_TYPED_TEST_H_
|
||||
#define GTEST_INCLUDE_GTEST_GTEST_TYPED_TEST_H_
|
||||
|
||||
// This header implements typed tests and type-parameterized tests.
|
||||
|
||||
// Typed (aka type-driven) tests repeat the same test for types in a
|
||||
// list. You must know which types you want to test with when writing
|
||||
// typed tests. Here's how you do it:
|
||||
|
||||
#if 0
|
||||
|
||||
// First, define a fixture class template. It should be parameterized
|
||||
// by a type. Remember to derive it from testing::Test.
|
||||
template <typename T>
|
||||
class FooTest : public testing::Test {
|
||||
public:
|
||||
...
|
||||
typedef std::list<T> List;
|
||||
static T shared_;
|
||||
T value_;
|
||||
};
|
||||
|
||||
// Next, associate a list of types with the test suite, which will be
|
||||
// repeated for each type in the list. The typedef is necessary for
|
||||
// the macro to parse correctly.
|
||||
typedef testing::Types<char, int, unsigned int> MyTypes;
|
||||
TYPED_TEST_SUITE(FooTest, MyTypes);
|
||||
|
||||
// If the type list contains only one type, you can write that type
|
||||
// directly without Types<...>:
|
||||
// TYPED_TEST_SUITE(FooTest, int);
|
||||
|
||||
// Then, use TYPED_TEST() instead of TEST_F() to define as many typed
|
||||
// tests for this test suite as you want.
|
||||
TYPED_TEST(FooTest, DoesBlah) {
|
||||
// Inside a test, refer to the special name TypeParam to get the type
|
||||
// parameter. Since we are inside a derived class template, C++ requires
|
||||
// us to visit the members of FooTest via 'this'.
|
||||
TypeParam n = this->value_;
|
||||
|
||||
// To visit static members of the fixture, add the TestFixture::
|
||||
// prefix.
|
||||
n += TestFixture::shared_;
|
||||
|
||||
// To refer to typedefs in the fixture, add the "typename
|
||||
// TestFixture::" prefix.
|
||||
typename TestFixture::List values;
|
||||
values.push_back(n);
|
||||
...
|
||||
}
|
||||
|
||||
TYPED_TEST(FooTest, HasPropertyA) { ... }
|
||||
|
||||
// TYPED_TEST_SUITE takes an optional third argument which allows to specify a
|
||||
// class that generates custom test name suffixes based on the type. This should
|
||||
// be a class which has a static template function GetName(int index) returning
|
||||
// a string for each type. The provided integer index equals the index of the
|
||||
// type in the provided type list. In many cases the index can be ignored.
|
||||
//
|
||||
// For example:
|
||||
// class MyTypeNames {
|
||||
// public:
|
||||
// template <typename T>
|
||||
// static std::string GetName(int) {
|
||||
// if (std::is_same<T, char>()) return "char";
|
||||
// if (std::is_same<T, int>()) return "int";
|
||||
// if (std::is_same<T, unsigned int>()) return "unsignedInt";
|
||||
// }
|
||||
// };
|
||||
// TYPED_TEST_SUITE(FooTest, MyTypes, MyTypeNames);
|
||||
|
||||
#endif // 0
|
||||
|
||||
// Type-parameterized tests are abstract test patterns parameterized
|
||||
// by a type. Compared with typed tests, type-parameterized tests
|
||||
// allow you to define the test pattern without knowing what the type
|
||||
// parameters are. The defined pattern can be instantiated with
|
||||
// different types any number of times, in any number of translation
|
||||
// units.
|
||||
//
|
||||
// If you are designing an interface or concept, you can define a
|
||||
// suite of type-parameterized tests to verify properties that any
|
||||
// valid implementation of the interface/concept should have. Then,
|
||||
// each implementation can easily instantiate the test suite to verify
|
||||
// that it conforms to the requirements, without having to write
|
||||
// similar tests repeatedly. Here's an example:
|
||||
|
||||
#if 0
|
||||
|
||||
// First, define a fixture class template. It should be parameterized
|
||||
// by a type. Remember to derive it from testing::Test.
|
||||
template <typename T>
|
||||
class FooTest : public testing::Test {
|
||||
...
|
||||
};
|
||||
|
||||
// Next, declare that you will define a type-parameterized test suite
|
||||
// (the _P suffix is for "parameterized" or "pattern", whichever you
|
||||
// prefer):
|
||||
TYPED_TEST_SUITE_P(FooTest);
|
||||
|
||||
// Then, use TYPED_TEST_P() to define as many type-parameterized tests
|
||||
// for this type-parameterized test suite as you want.
|
||||
TYPED_TEST_P(FooTest, DoesBlah) {
|
||||
// Inside a test, refer to TypeParam to get the type parameter.
|
||||
TypeParam n = 0;
|
||||
...
|
||||
}
|
||||
|
||||
TYPED_TEST_P(FooTest, HasPropertyA) { ... }
|
||||
|
||||
// Now the tricky part: you need to register all test patterns before
|
||||
// you can instantiate them. The first argument of the macro is the
|
||||
// test suite name; the rest are the names of the tests in this test
|
||||
// case.
|
||||
REGISTER_TYPED_TEST_SUITE_P(FooTest,
|
||||
DoesBlah, HasPropertyA);
|
||||
|
||||
// Finally, you are free to instantiate the pattern with the types you
|
||||
// want. If you put the above code in a header file, you can #include
|
||||
// it in multiple C++ source files and instantiate it multiple times.
|
||||
//
|
||||
// To distinguish different instances of the pattern, the first
|
||||
// argument to the INSTANTIATE_* macro is a prefix that will be added
|
||||
// to the actual test suite name. Remember to pick unique prefixes for
|
||||
// different instances.
|
||||
typedef testing::Types<char, int, unsigned int> MyTypes;
|
||||
INSTANTIATE_TYPED_TEST_SUITE_P(My, FooTest, MyTypes);
|
||||
|
||||
// If the type list contains only one type, you can write that type
|
||||
// directly without Types<...>:
|
||||
// INSTANTIATE_TYPED_TEST_SUITE_P(My, FooTest, int);
|
||||
//
|
||||
// Similar to the optional argument of TYPED_TEST_SUITE above,
|
||||
// INSTANTIATE_TEST_SUITE_P takes an optional fourth argument which allows to
|
||||
// generate custom names.
|
||||
// INSTANTIATE_TYPED_TEST_SUITE_P(My, FooTest, MyTypes, MyTypeNames);
|
||||
|
||||
#endif // 0
|
||||
|
||||
#include "gtest/internal/gtest-port.h"
|
||||
#include "gtest/internal/gtest-type-util.h"
|
||||
|
||||
// Implements typed tests.
|
||||
|
||||
#if GTEST_HAS_TYPED_TEST
|
||||
|
||||
// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
|
||||
//
|
||||
// Expands to the name of the typedef for the type parameters of the
|
||||
// given test suite.
|
||||
#define GTEST_TYPE_PARAMS_(TestSuiteName) gtest_type_params_##TestSuiteName##_
|
||||
|
||||
// Expands to the name of the typedef for the NameGenerator, responsible for
|
||||
// creating the suffixes of the name.
|
||||
#define GTEST_NAME_GENERATOR_(TestSuiteName) \
|
||||
gtest_type_params_##TestSuiteName##_NameGenerator
|
||||
|
||||
#define TYPED_TEST_SUITE(CaseName, Types, ...) \
|
||||
typedef ::testing::internal::TypeList<Types>::type GTEST_TYPE_PARAMS_( \
|
||||
CaseName); \
|
||||
typedef ::testing::internal::NameGeneratorSelector<__VA_ARGS__>::type \
|
||||
GTEST_NAME_GENERATOR_(CaseName)
|
||||
|
||||
# define TYPED_TEST(CaseName, TestName) \
|
||||
template <typename gtest_TypeParam_> \
|
||||
class GTEST_TEST_CLASS_NAME_(CaseName, TestName) \
|
||||
: public CaseName<gtest_TypeParam_> { \
|
||||
private: \
|
||||
typedef CaseName<gtest_TypeParam_> TestFixture; \
|
||||
typedef gtest_TypeParam_ TypeParam; \
|
||||
virtual void TestBody(); \
|
||||
}; \
|
||||
static bool gtest_##CaseName##_##TestName##_registered_ \
|
||||
GTEST_ATTRIBUTE_UNUSED_ = \
|
||||
::testing::internal::TypeParameterizedTest< \
|
||||
CaseName, \
|
||||
::testing::internal::TemplateSel<GTEST_TEST_CLASS_NAME_(CaseName, \
|
||||
TestName)>, \
|
||||
GTEST_TYPE_PARAMS_( \
|
||||
CaseName)>::Register("", \
|
||||
::testing::internal::CodeLocation( \
|
||||
__FILE__, __LINE__), \
|
||||
#CaseName, #TestName, 0, \
|
||||
::testing::internal::GenerateNames< \
|
||||
GTEST_NAME_GENERATOR_(CaseName), \
|
||||
GTEST_TYPE_PARAMS_(CaseName)>()); \
|
||||
template <typename gtest_TypeParam_> \
|
||||
void GTEST_TEST_CLASS_NAME_(CaseName, \
|
||||
TestName)<gtest_TypeParam_>::TestBody()
|
||||
|
||||
// Legacy API is deprecated but still available
|
||||
#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
|
||||
#define TYPED_TEST_CASE \
|
||||
static_assert(::testing::internal::TypedTestCaseIsDeprecated(), ""); \
|
||||
TYPED_TEST_SUITE
|
||||
#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
|
||||
|
||||
#endif // GTEST_HAS_TYPED_TEST
|
||||
|
||||
// Implements type-parameterized tests.
|
||||
|
||||
#if GTEST_HAS_TYPED_TEST_P
|
||||
|
||||
// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
|
||||
//
|
||||
// Expands to the namespace name that the type-parameterized tests for
|
||||
// the given type-parameterized test suite are defined in. The exact
|
||||
// name of the namespace is subject to change without notice.
|
||||
#define GTEST_SUITE_NAMESPACE_(TestSuiteName) gtest_suite_##TestSuiteName##_
|
||||
|
||||
// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
|
||||
//
|
||||
// Expands to the name of the variable used to remember the names of
|
||||
// the defined tests in the given test suite.
|
||||
#define GTEST_TYPED_TEST_SUITE_P_STATE_(TestSuiteName) \
|
||||
gtest_typed_test_suite_p_state_##TestSuiteName##_
|
||||
|
||||
// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE DIRECTLY.
|
||||
//
|
||||
// Expands to the name of the variable used to remember the names of
|
||||
// the registered tests in the given test suite.
|
||||
#define GTEST_REGISTERED_TEST_NAMES_(TestSuiteName) \
|
||||
gtest_registered_test_names_##TestSuiteName##_
|
||||
|
||||
// The variables defined in the type-parameterized test macros are
|
||||
// static as typically these macros are used in a .h file that can be
|
||||
// #included in multiple translation units linked together.
|
||||
#define TYPED_TEST_SUITE_P(SuiteName) \
|
||||
static ::testing::internal::TypedTestSuitePState \
|
||||
GTEST_TYPED_TEST_SUITE_P_STATE_(SuiteName)
|
||||
|
||||
// Legacy API is deprecated but still available
|
||||
#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
|
||||
#define TYPED_TEST_CASE_P \
|
||||
static_assert(::testing::internal::TypedTestCase_P_IsDeprecated(), ""); \
|
||||
TYPED_TEST_SUITE_P
|
||||
#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
|
||||
|
||||
#define TYPED_TEST_P(SuiteName, TestName) \
|
||||
namespace GTEST_SUITE_NAMESPACE_(SuiteName) { \
|
||||
template <typename gtest_TypeParam_> \
|
||||
class TestName : public SuiteName<gtest_TypeParam_> { \
|
||||
private: \
|
||||
typedef SuiteName<gtest_TypeParam_> TestFixture; \
|
||||
typedef gtest_TypeParam_ TypeParam; \
|
||||
virtual void TestBody(); \
|
||||
}; \
|
||||
static bool gtest_##TestName##_defined_ GTEST_ATTRIBUTE_UNUSED_ = \
|
||||
GTEST_TYPED_TEST_SUITE_P_STATE_(SuiteName).AddTestName( \
|
||||
__FILE__, __LINE__, #SuiteName, #TestName); \
|
||||
} \
|
||||
template <typename gtest_TypeParam_> \
|
||||
void GTEST_SUITE_NAMESPACE_( \
|
||||
SuiteName)::TestName<gtest_TypeParam_>::TestBody()
|
||||
|
||||
#define REGISTER_TYPED_TEST_SUITE_P(SuiteName, ...) \
|
||||
namespace GTEST_SUITE_NAMESPACE_(SuiteName) { \
|
||||
typedef ::testing::internal::Templates<__VA_ARGS__>::type gtest_AllTests_; \
|
||||
} \
|
||||
static const char* const GTEST_REGISTERED_TEST_NAMES_( \
|
||||
SuiteName) GTEST_ATTRIBUTE_UNUSED_ = \
|
||||
GTEST_TYPED_TEST_SUITE_P_STATE_(SuiteName).VerifyRegisteredTestNames( \
|
||||
__FILE__, __LINE__, #__VA_ARGS__)
|
||||
|
||||
// Legacy API is deprecated but still available
|
||||
#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
|
||||
#define REGISTER_TYPED_TEST_CASE_P \
|
||||
static_assert(::testing::internal::RegisterTypedTestCase_P_IsDeprecated(), \
|
||||
""); \
|
||||
REGISTER_TYPED_TEST_SUITE_P
|
||||
#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
|
||||
|
||||
#define INSTANTIATE_TYPED_TEST_SUITE_P(Prefix, SuiteName, Types, ...) \
|
||||
static bool gtest_##Prefix##_##SuiteName GTEST_ATTRIBUTE_UNUSED_ = \
|
||||
::testing::internal::TypeParameterizedTestSuite< \
|
||||
SuiteName, GTEST_SUITE_NAMESPACE_(SuiteName)::gtest_AllTests_, \
|
||||
::testing::internal::TypeList<Types>::type>:: \
|
||||
Register(#Prefix, \
|
||||
::testing::internal::CodeLocation(__FILE__, __LINE__), \
|
||||
>EST_TYPED_TEST_SUITE_P_STATE_(SuiteName), #SuiteName, \
|
||||
GTEST_REGISTERED_TEST_NAMES_(SuiteName), \
|
||||
::testing::internal::GenerateNames< \
|
||||
::testing::internal::NameGeneratorSelector< \
|
||||
__VA_ARGS__>::type, \
|
||||
::testing::internal::TypeList<Types>::type>())
|
||||
|
||||
// Legacy API is deprecated but still available
|
||||
#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
|
||||
#define INSTANTIATE_TYPED_TEST_CASE_P \
|
||||
static_assert( \
|
||||
::testing::internal::InstantiateTypedTestCase_P_IsDeprecated(), ""); \
|
||||
INSTANTIATE_TYPED_TEST_SUITE_P
|
||||
#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
|
||||
|
||||
#endif // GTEST_HAS_TYPED_TEST_P
|
||||
|
||||
#endif // GTEST_INCLUDE_GTEST_GTEST_TYPED_TEST_H_
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,359 +0,0 @@
|
||||
// Copyright 2006, Google Inc.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// This file is AUTOMATICALLY GENERATED on 01/02/2019 by command
|
||||
// 'gen_gtest_pred_impl.py 5'. DO NOT EDIT BY HAND!
|
||||
//
|
||||
// Implements a family of generic predicate assertion macros.
|
||||
// GOOGLETEST_CM0001 DO NOT DELETE
|
||||
|
||||
#ifndef GTEST_INCLUDE_GTEST_GTEST_PRED_IMPL_H_
|
||||
#define GTEST_INCLUDE_GTEST_GTEST_PRED_IMPL_H_
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
namespace testing {
|
||||
|
||||
// This header implements a family of generic predicate assertion
|
||||
// macros:
|
||||
//
|
||||
// ASSERT_PRED_FORMAT1(pred_format, v1)
|
||||
// ASSERT_PRED_FORMAT2(pred_format, v1, v2)
|
||||
// ...
|
||||
//
|
||||
// where pred_format is a function or functor that takes n (in the
|
||||
// case of ASSERT_PRED_FORMATn) values and their source expression
|
||||
// text, and returns a testing::AssertionResult. See the definition
|
||||
// of ASSERT_EQ in gtest.h for an example.
|
||||
//
|
||||
// If you don't care about formatting, you can use the more
|
||||
// restrictive version:
|
||||
//
|
||||
// ASSERT_PRED1(pred, v1)
|
||||
// ASSERT_PRED2(pred, v1, v2)
|
||||
// ...
|
||||
//
|
||||
// where pred is an n-ary function or functor that returns bool,
|
||||
// and the values v1, v2, ..., must support the << operator for
|
||||
// streaming to std::ostream.
|
||||
//
|
||||
// We also define the EXPECT_* variations.
|
||||
//
|
||||
// For now we only support predicates whose arity is at most 5.
|
||||
// Please email googletestframework@googlegroups.com if you need
|
||||
// support for higher arities.
|
||||
|
||||
// GTEST_ASSERT_ is the basic statement to which all of the assertions
|
||||
// in this file reduce. Don't use this in your code.
|
||||
|
||||
#define GTEST_ASSERT_(expression, on_failure) \
|
||||
GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
|
||||
if (const ::testing::AssertionResult gtest_ar = (expression)) \
|
||||
; \
|
||||
else \
|
||||
on_failure(gtest_ar.failure_message())
|
||||
|
||||
|
||||
// Helper function for implementing {EXPECT|ASSERT}_PRED1. Don't use
|
||||
// this in your code.
|
||||
template <typename Pred,
|
||||
typename T1>
|
||||
AssertionResult AssertPred1Helper(const char* pred_text,
|
||||
const char* e1,
|
||||
Pred pred,
|
||||
const T1& v1) {
|
||||
if (pred(v1)) return AssertionSuccess();
|
||||
|
||||
return AssertionFailure()
|
||||
<< pred_text << "(" << e1 << ") evaluates to false, where"
|
||||
<< "\n"
|
||||
<< e1 << " evaluates to " << ::testing::PrintToString(v1);
|
||||
}
|
||||
|
||||
// Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT1.
|
||||
// Don't use this in your code.
|
||||
#define GTEST_PRED_FORMAT1_(pred_format, v1, on_failure)\
|
||||
GTEST_ASSERT_(pred_format(#v1, v1), \
|
||||
on_failure)
|
||||
|
||||
// Internal macro for implementing {EXPECT|ASSERT}_PRED1. Don't use
|
||||
// this in your code.
|
||||
#define GTEST_PRED1_(pred, v1, on_failure)\
|
||||
GTEST_ASSERT_(::testing::AssertPred1Helper(#pred, \
|
||||
#v1, \
|
||||
pred, \
|
||||
v1), on_failure)
|
||||
|
||||
// Unary predicate assertion macros.
|
||||
#define EXPECT_PRED_FORMAT1(pred_format, v1) \
|
||||
GTEST_PRED_FORMAT1_(pred_format, v1, GTEST_NONFATAL_FAILURE_)
|
||||
#define EXPECT_PRED1(pred, v1) \
|
||||
GTEST_PRED1_(pred, v1, GTEST_NONFATAL_FAILURE_)
|
||||
#define ASSERT_PRED_FORMAT1(pred_format, v1) \
|
||||
GTEST_PRED_FORMAT1_(pred_format, v1, GTEST_FATAL_FAILURE_)
|
||||
#define ASSERT_PRED1(pred, v1) \
|
||||
GTEST_PRED1_(pred, v1, GTEST_FATAL_FAILURE_)
|
||||
|
||||
|
||||
|
||||
// Helper function for implementing {EXPECT|ASSERT}_PRED2. Don't use
|
||||
// this in your code.
|
||||
template <typename Pred,
|
||||
typename T1,
|
||||
typename T2>
|
||||
AssertionResult AssertPred2Helper(const char* pred_text,
|
||||
const char* e1,
|
||||
const char* e2,
|
||||
Pred pred,
|
||||
const T1& v1,
|
||||
const T2& v2) {
|
||||
if (pred(v1, v2)) return AssertionSuccess();
|
||||
|
||||
return AssertionFailure()
|
||||
<< pred_text << "(" << e1 << ", " << e2
|
||||
<< ") evaluates to false, where"
|
||||
<< "\n"
|
||||
<< e1 << " evaluates to " << ::testing::PrintToString(v1) << "\n"
|
||||
<< e2 << " evaluates to " << ::testing::PrintToString(v2);
|
||||
}
|
||||
|
||||
// Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT2.
|
||||
// Don't use this in your code.
|
||||
#define GTEST_PRED_FORMAT2_(pred_format, v1, v2, on_failure)\
|
||||
GTEST_ASSERT_(pred_format(#v1, #v2, v1, v2), \
|
||||
on_failure)
|
||||
|
||||
// Internal macro for implementing {EXPECT|ASSERT}_PRED2. Don't use
|
||||
// this in your code.
|
||||
#define GTEST_PRED2_(pred, v1, v2, on_failure)\
|
||||
GTEST_ASSERT_(::testing::AssertPred2Helper(#pred, \
|
||||
#v1, \
|
||||
#v2, \
|
||||
pred, \
|
||||
v1, \
|
||||
v2), on_failure)
|
||||
|
||||
// Binary predicate assertion macros.
|
||||
#define EXPECT_PRED_FORMAT2(pred_format, v1, v2) \
|
||||
GTEST_PRED_FORMAT2_(pred_format, v1, v2, GTEST_NONFATAL_FAILURE_)
|
||||
#define EXPECT_PRED2(pred, v1, v2) \
|
||||
GTEST_PRED2_(pred, v1, v2, GTEST_NONFATAL_FAILURE_)
|
||||
#define ASSERT_PRED_FORMAT2(pred_format, v1, v2) \
|
||||
GTEST_PRED_FORMAT2_(pred_format, v1, v2, GTEST_FATAL_FAILURE_)
|
||||
#define ASSERT_PRED2(pred, v1, v2) \
|
||||
GTEST_PRED2_(pred, v1, v2, GTEST_FATAL_FAILURE_)
|
||||
|
||||
|
||||
|
||||
// Helper function for implementing {EXPECT|ASSERT}_PRED3. Don't use
|
||||
// this in your code.
|
||||
template <typename Pred,
|
||||
typename T1,
|
||||
typename T2,
|
||||
typename T3>
|
||||
AssertionResult AssertPred3Helper(const char* pred_text,
|
||||
const char* e1,
|
||||
const char* e2,
|
||||
const char* e3,
|
||||
Pred pred,
|
||||
const T1& v1,
|
||||
const T2& v2,
|
||||
const T3& v3) {
|
||||
if (pred(v1, v2, v3)) return AssertionSuccess();
|
||||
|
||||
return AssertionFailure()
|
||||
<< pred_text << "(" << e1 << ", " << e2 << ", " << e3
|
||||
<< ") evaluates to false, where"
|
||||
<< "\n"
|
||||
<< e1 << " evaluates to " << ::testing::PrintToString(v1) << "\n"
|
||||
<< e2 << " evaluates to " << ::testing::PrintToString(v2) << "\n"
|
||||
<< e3 << " evaluates to " << ::testing::PrintToString(v3);
|
||||
}
|
||||
|
||||
// Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT3.
|
||||
// Don't use this in your code.
|
||||
#define GTEST_PRED_FORMAT3_(pred_format, v1, v2, v3, on_failure)\
|
||||
GTEST_ASSERT_(pred_format(#v1, #v2, #v3, v1, v2, v3), \
|
||||
on_failure)
|
||||
|
||||
// Internal macro for implementing {EXPECT|ASSERT}_PRED3. Don't use
|
||||
// this in your code.
|
||||
#define GTEST_PRED3_(pred, v1, v2, v3, on_failure)\
|
||||
GTEST_ASSERT_(::testing::AssertPred3Helper(#pred, \
|
||||
#v1, \
|
||||
#v2, \
|
||||
#v3, \
|
||||
pred, \
|
||||
v1, \
|
||||
v2, \
|
||||
v3), on_failure)
|
||||
|
||||
// Ternary predicate assertion macros.
|
||||
#define EXPECT_PRED_FORMAT3(pred_format, v1, v2, v3) \
|
||||
GTEST_PRED_FORMAT3_(pred_format, v1, v2, v3, GTEST_NONFATAL_FAILURE_)
|
||||
#define EXPECT_PRED3(pred, v1, v2, v3) \
|
||||
GTEST_PRED3_(pred, v1, v2, v3, GTEST_NONFATAL_FAILURE_)
|
||||
#define ASSERT_PRED_FORMAT3(pred_format, v1, v2, v3) \
|
||||
GTEST_PRED_FORMAT3_(pred_format, v1, v2, v3, GTEST_FATAL_FAILURE_)
|
||||
#define ASSERT_PRED3(pred, v1, v2, v3) \
|
||||
GTEST_PRED3_(pred, v1, v2, v3, GTEST_FATAL_FAILURE_)
|
||||
|
||||
|
||||
|
||||
// Helper function for implementing {EXPECT|ASSERT}_PRED4. Don't use
|
||||
// this in your code.
|
||||
template <typename Pred,
|
||||
typename T1,
|
||||
typename T2,
|
||||
typename T3,
|
||||
typename T4>
|
||||
AssertionResult AssertPred4Helper(const char* pred_text,
|
||||
const char* e1,
|
||||
const char* e2,
|
||||
const char* e3,
|
||||
const char* e4,
|
||||
Pred pred,
|
||||
const T1& v1,
|
||||
const T2& v2,
|
||||
const T3& v3,
|
||||
const T4& v4) {
|
||||
if (pred(v1, v2, v3, v4)) return AssertionSuccess();
|
||||
|
||||
return AssertionFailure()
|
||||
<< pred_text << "(" << e1 << ", " << e2 << ", " << e3 << ", " << e4
|
||||
<< ") evaluates to false, where"
|
||||
<< "\n"
|
||||
<< e1 << " evaluates to " << ::testing::PrintToString(v1) << "\n"
|
||||
<< e2 << " evaluates to " << ::testing::PrintToString(v2) << "\n"
|
||||
<< e3 << " evaluates to " << ::testing::PrintToString(v3) << "\n"
|
||||
<< e4 << " evaluates to " << ::testing::PrintToString(v4);
|
||||
}
|
||||
|
||||
// Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT4.
|
||||
// Don't use this in your code.
|
||||
#define GTEST_PRED_FORMAT4_(pred_format, v1, v2, v3, v4, on_failure)\
|
||||
GTEST_ASSERT_(pred_format(#v1, #v2, #v3, #v4, v1, v2, v3, v4), \
|
||||
on_failure)
|
||||
|
||||
// Internal macro for implementing {EXPECT|ASSERT}_PRED4. Don't use
|
||||
// this in your code.
|
||||
#define GTEST_PRED4_(pred, v1, v2, v3, v4, on_failure)\
|
||||
GTEST_ASSERT_(::testing::AssertPred4Helper(#pred, \
|
||||
#v1, \
|
||||
#v2, \
|
||||
#v3, \
|
||||
#v4, \
|
||||
pred, \
|
||||
v1, \
|
||||
v2, \
|
||||
v3, \
|
||||
v4), on_failure)
|
||||
|
||||
// 4-ary predicate assertion macros.
|
||||
#define EXPECT_PRED_FORMAT4(pred_format, v1, v2, v3, v4) \
|
||||
GTEST_PRED_FORMAT4_(pred_format, v1, v2, v3, v4, GTEST_NONFATAL_FAILURE_)
|
||||
#define EXPECT_PRED4(pred, v1, v2, v3, v4) \
|
||||
GTEST_PRED4_(pred, v1, v2, v3, v4, GTEST_NONFATAL_FAILURE_)
|
||||
#define ASSERT_PRED_FORMAT4(pred_format, v1, v2, v3, v4) \
|
||||
GTEST_PRED_FORMAT4_(pred_format, v1, v2, v3, v4, GTEST_FATAL_FAILURE_)
|
||||
#define ASSERT_PRED4(pred, v1, v2, v3, v4) \
|
||||
GTEST_PRED4_(pred, v1, v2, v3, v4, GTEST_FATAL_FAILURE_)
|
||||
|
||||
|
||||
|
||||
// Helper function for implementing {EXPECT|ASSERT}_PRED5. Don't use
|
||||
// this in your code.
|
||||
template <typename Pred,
|
||||
typename T1,
|
||||
typename T2,
|
||||
typename T3,
|
||||
typename T4,
|
||||
typename T5>
|
||||
AssertionResult AssertPred5Helper(const char* pred_text,
|
||||
const char* e1,
|
||||
const char* e2,
|
||||
const char* e3,
|
||||
const char* e4,
|
||||
const char* e5,
|
||||
Pred pred,
|
||||
const T1& v1,
|
||||
const T2& v2,
|
||||
const T3& v3,
|
||||
const T4& v4,
|
||||
const T5& v5) {
|
||||
if (pred(v1, v2, v3, v4, v5)) return AssertionSuccess();
|
||||
|
||||
return AssertionFailure()
|
||||
<< pred_text << "(" << e1 << ", " << e2 << ", " << e3 << ", " << e4
|
||||
<< ", " << e5 << ") evaluates to false, where"
|
||||
<< "\n"
|
||||
<< e1 << " evaluates to " << ::testing::PrintToString(v1) << "\n"
|
||||
<< e2 << " evaluates to " << ::testing::PrintToString(v2) << "\n"
|
||||
<< e3 << " evaluates to " << ::testing::PrintToString(v3) << "\n"
|
||||
<< e4 << " evaluates to " << ::testing::PrintToString(v4) << "\n"
|
||||
<< e5 << " evaluates to " << ::testing::PrintToString(v5);
|
||||
}
|
||||
|
||||
// Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT5.
|
||||
// Don't use this in your code.
|
||||
#define GTEST_PRED_FORMAT5_(pred_format, v1, v2, v3, v4, v5, on_failure)\
|
||||
GTEST_ASSERT_(pred_format(#v1, #v2, #v3, #v4, #v5, v1, v2, v3, v4, v5), \
|
||||
on_failure)
|
||||
|
||||
// Internal macro for implementing {EXPECT|ASSERT}_PRED5. Don't use
|
||||
// this in your code.
|
||||
#define GTEST_PRED5_(pred, v1, v2, v3, v4, v5, on_failure)\
|
||||
GTEST_ASSERT_(::testing::AssertPred5Helper(#pred, \
|
||||
#v1, \
|
||||
#v2, \
|
||||
#v3, \
|
||||
#v4, \
|
||||
#v5, \
|
||||
pred, \
|
||||
v1, \
|
||||
v2, \
|
||||
v3, \
|
||||
v4, \
|
||||
v5), on_failure)
|
||||
|
||||
// 5-ary predicate assertion macros.
|
||||
#define EXPECT_PRED_FORMAT5(pred_format, v1, v2, v3, v4, v5) \
|
||||
GTEST_PRED_FORMAT5_(pred_format, v1, v2, v3, v4, v5, GTEST_NONFATAL_FAILURE_)
|
||||
#define EXPECT_PRED5(pred, v1, v2, v3, v4, v5) \
|
||||
GTEST_PRED5_(pred, v1, v2, v3, v4, v5, GTEST_NONFATAL_FAILURE_)
|
||||
#define ASSERT_PRED_FORMAT5(pred_format, v1, v2, v3, v4, v5) \
|
||||
GTEST_PRED_FORMAT5_(pred_format, v1, v2, v3, v4, v5, GTEST_FATAL_FAILURE_)
|
||||
#define ASSERT_PRED5(pred, v1, v2, v3, v4, v5) \
|
||||
GTEST_PRED5_(pred, v1, v2, v3, v4, v5, GTEST_FATAL_FAILURE_)
|
||||
|
||||
|
||||
|
||||
} // namespace testing
|
||||
|
||||
#endif // GTEST_INCLUDE_GTEST_GTEST_PRED_IMPL_H_
|
||||
@@ -1,61 +0,0 @@
|
||||
// Copyright 2006, Google Inc.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
//
|
||||
// Google C++ Testing and Mocking Framework definitions useful in production code.
|
||||
// GOOGLETEST_CM0003 DO NOT DELETE
|
||||
|
||||
#ifndef GTEST_INCLUDE_GTEST_GTEST_PROD_H_
|
||||
#define GTEST_INCLUDE_GTEST_GTEST_PROD_H_
|
||||
|
||||
// When you need to test the private or protected members of a class,
|
||||
// use the FRIEND_TEST macro to declare your tests as friends of the
|
||||
// class. For example:
|
||||
//
|
||||
// class MyClass {
|
||||
// private:
|
||||
// void PrivateMethod();
|
||||
// FRIEND_TEST(MyClassTest, PrivateMethodWorks);
|
||||
// };
|
||||
//
|
||||
// class MyClassTest : public testing::Test {
|
||||
// // ...
|
||||
// };
|
||||
//
|
||||
// TEST_F(MyClassTest, PrivateMethodWorks) {
|
||||
// // Can call MyClass::PrivateMethod() here.
|
||||
// }
|
||||
//
|
||||
// Note: The test class must be in the same namespace as the class being tested.
|
||||
// For example, putting MyClassTest in an anonymous namespace will not work.
|
||||
|
||||
#define FRIEND_TEST(test_case_name, test_name)\
|
||||
friend class test_case_name##_##test_name##_Test
|
||||
|
||||
#endif // GTEST_INCLUDE_GTEST_GTEST_PROD_H_
|
||||
@@ -1,56 +0,0 @@
|
||||
# Customization Points
|
||||
|
||||
The custom directory is an injection point for custom user configurations.
|
||||
|
||||
## Header `gtest.h`
|
||||
|
||||
### The following macros can be defined:
|
||||
|
||||
* `GTEST_OS_STACK_TRACE_GETTER_` - The name of an implementation of
|
||||
`OsStackTraceGetterInterface`.
|
||||
* `GTEST_CUSTOM_TEMPDIR_FUNCTION_` - An override for `testing::TempDir()`. See
|
||||
`testing::TempDir` for semantics and signature.
|
||||
|
||||
## Header `gtest-port.h`
|
||||
|
||||
The following macros can be defined:
|
||||
|
||||
### Flag related macros:
|
||||
|
||||
* `GTEST_FLAG(flag_name)`
|
||||
* `GTEST_USE_OWN_FLAGFILE_FLAG_` - Define to 0 when the system provides its
|
||||
own flagfile flag parsing.
|
||||
* `GTEST_DECLARE_bool_(name)`
|
||||
* `GTEST_DECLARE_int32_(name)`
|
||||
* `GTEST_DECLARE_string_(name)`
|
||||
* `GTEST_DEFINE_bool_(name, default_val, doc)`
|
||||
* `GTEST_DEFINE_int32_(name, default_val, doc)`
|
||||
* `GTEST_DEFINE_string_(name, default_val, doc)`
|
||||
|
||||
### Logging:
|
||||
|
||||
* `GTEST_LOG_(severity)`
|
||||
* `GTEST_CHECK_(condition)`
|
||||
* Functions `LogToStderr()` and `FlushInfoLog()` have to be provided too.
|
||||
|
||||
### Threading:
|
||||
|
||||
* `GTEST_HAS_NOTIFICATION_` - Enabled if Notification is already provided.
|
||||
* `GTEST_HAS_MUTEX_AND_THREAD_LOCAL_` - Enabled if `Mutex` and `ThreadLocal`
|
||||
are already provided. Must also provide `GTEST_DECLARE_STATIC_MUTEX_(mutex)`
|
||||
and `GTEST_DEFINE_STATIC_MUTEX_(mutex)`
|
||||
* `GTEST_EXCLUSIVE_LOCK_REQUIRED_(locks)`
|
||||
* `GTEST_LOCK_EXCLUDED_(locks)`
|
||||
|
||||
### Underlying library support features
|
||||
|
||||
* `GTEST_HAS_CXXABI_H_`
|
||||
|
||||
### Exporting API symbols:
|
||||
|
||||
* `GTEST_API_` - Specifier for exported symbols.
|
||||
|
||||
## Header `gtest-printers.h`
|
||||
|
||||
* See documentation at `gtest/gtest-printers.h` for details on how to define a
|
||||
custom printer.
|
||||
@@ -1,37 +0,0 @@
|
||||
// Copyright 2015, Google Inc.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Injection point for custom user configurations. See README for details
|
||||
//
|
||||
// ** Custom implementation starts here **
|
||||
|
||||
#ifndef GTEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_PORT_H_
|
||||
#define GTEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_PORT_H_
|
||||
|
||||
#endif // GTEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_PORT_H_
|
||||
@@ -1,42 +0,0 @@
|
||||
// Copyright 2015, Google Inc.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// This file provides an injection point for custom printers in a local
|
||||
// installation of gTest.
|
||||
// It will be included from gtest-printers.h and the overrides in this file
|
||||
// will be visible to everyone.
|
||||
//
|
||||
// Injection point for custom user configurations. See README for details
|
||||
//
|
||||
// ** Custom implementation starts here **
|
||||
|
||||
#ifndef GTEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_PRINTERS_H_
|
||||
#define GTEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_PRINTERS_H_
|
||||
|
||||
#endif // GTEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_PRINTERS_H_
|
||||
@@ -1,37 +0,0 @@
|
||||
// Copyright 2015, Google Inc.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Injection point for custom user configurations. See README for details
|
||||
//
|
||||
// ** Custom implementation starts here **
|
||||
|
||||
#ifndef GTEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_H_
|
||||
#define GTEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_H_
|
||||
|
||||
#endif // GTEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_H_
|
||||
@@ -1,304 +0,0 @@
|
||||
// Copyright 2005, Google Inc.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// The Google C++ Testing and Mocking Framework (Google Test)
|
||||
//
|
||||
// This header file defines internal utilities needed for implementing
|
||||
// death tests. They are subject to change without notice.
|
||||
// GOOGLETEST_CM0001 DO NOT DELETE
|
||||
|
||||
#ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_DEATH_TEST_INTERNAL_H_
|
||||
#define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_DEATH_TEST_INTERNAL_H_
|
||||
|
||||
#include "gtest/gtest-matchers.h"
|
||||
#include "gtest/internal/gtest-internal.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <memory>
|
||||
|
||||
namespace testing {
|
||||
namespace internal {
|
||||
|
||||
GTEST_DECLARE_string_(internal_run_death_test);
|
||||
|
||||
// Names of the flags (needed for parsing Google Test flags).
|
||||
const char kDeathTestStyleFlag[] = "death_test_style";
|
||||
const char kDeathTestUseFork[] = "death_test_use_fork";
|
||||
const char kInternalRunDeathTestFlag[] = "internal_run_death_test";
|
||||
|
||||
#if GTEST_HAS_DEATH_TEST
|
||||
|
||||
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251 \
|
||||
/* class A needs to have dll-interface to be used by clients of class B */)
|
||||
|
||||
// DeathTest is a class that hides much of the complexity of the
|
||||
// GTEST_DEATH_TEST_ macro. It is abstract; its static Create method
|
||||
// returns a concrete class that depends on the prevailing death test
|
||||
// style, as defined by the --gtest_death_test_style and/or
|
||||
// --gtest_internal_run_death_test flags.
|
||||
|
||||
// In describing the results of death tests, these terms are used with
|
||||
// the corresponding definitions:
|
||||
//
|
||||
// exit status: The integer exit information in the format specified
|
||||
// by wait(2)
|
||||
// exit code: The integer code passed to exit(3), _exit(2), or
|
||||
// returned from main()
|
||||
class GTEST_API_ DeathTest {
|
||||
public:
|
||||
// Create returns false if there was an error determining the
|
||||
// appropriate action to take for the current death test; for example,
|
||||
// if the gtest_death_test_style flag is set to an invalid value.
|
||||
// The LastMessage method will return a more detailed message in that
|
||||
// case. Otherwise, the DeathTest pointer pointed to by the "test"
|
||||
// argument is set. If the death test should be skipped, the pointer
|
||||
// is set to NULL; otherwise, it is set to the address of a new concrete
|
||||
// DeathTest object that controls the execution of the current test.
|
||||
static bool Create(const char* statement, Matcher<const std::string&> matcher,
|
||||
const char* file, int line, DeathTest** test);
|
||||
DeathTest();
|
||||
virtual ~DeathTest() { }
|
||||
|
||||
// A helper class that aborts a death test when it's deleted.
|
||||
class ReturnSentinel {
|
||||
public:
|
||||
explicit ReturnSentinel(DeathTest* test) : test_(test) { }
|
||||
~ReturnSentinel() { test_->Abort(TEST_ENCOUNTERED_RETURN_STATEMENT); }
|
||||
private:
|
||||
DeathTest* const test_;
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(ReturnSentinel);
|
||||
} GTEST_ATTRIBUTE_UNUSED_;
|
||||
|
||||
// An enumeration of possible roles that may be taken when a death
|
||||
// test is encountered. EXECUTE means that the death test logic should
|
||||
// be executed immediately. OVERSEE means that the program should prepare
|
||||
// the appropriate environment for a child process to execute the death
|
||||
// test, then wait for it to complete.
|
||||
enum TestRole { OVERSEE_TEST, EXECUTE_TEST };
|
||||
|
||||
// An enumeration of the three reasons that a test might be aborted.
|
||||
enum AbortReason {
|
||||
TEST_ENCOUNTERED_RETURN_STATEMENT,
|
||||
TEST_THREW_EXCEPTION,
|
||||
TEST_DID_NOT_DIE
|
||||
};
|
||||
|
||||
// Assumes one of the above roles.
|
||||
virtual TestRole AssumeRole() = 0;
|
||||
|
||||
// Waits for the death test to finish and returns its status.
|
||||
virtual int Wait() = 0;
|
||||
|
||||
// Returns true if the death test passed; that is, the test process
|
||||
// exited during the test, its exit status matches a user-supplied
|
||||
// predicate, and its stderr output matches a user-supplied regular
|
||||
// expression.
|
||||
// The user-supplied predicate may be a macro expression rather
|
||||
// than a function pointer or functor, or else Wait and Passed could
|
||||
// be combined.
|
||||
virtual bool Passed(bool exit_status_ok) = 0;
|
||||
|
||||
// Signals that the death test did not die as expected.
|
||||
virtual void Abort(AbortReason reason) = 0;
|
||||
|
||||
// Returns a human-readable outcome message regarding the outcome of
|
||||
// the last death test.
|
||||
static const char* LastMessage();
|
||||
|
||||
static void set_last_death_test_message(const std::string& message);
|
||||
|
||||
private:
|
||||
// A string containing a description of the outcome of the last death test.
|
||||
static std::string last_death_test_message_;
|
||||
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(DeathTest);
|
||||
};
|
||||
|
||||
GTEST_DISABLE_MSC_WARNINGS_POP_() // 4251
|
||||
|
||||
// Factory interface for death tests. May be mocked out for testing.
|
||||
class DeathTestFactory {
|
||||
public:
|
||||
virtual ~DeathTestFactory() { }
|
||||
virtual bool Create(const char* statement,
|
||||
Matcher<const std::string&> matcher, const char* file,
|
||||
int line, DeathTest** test) = 0;
|
||||
};
|
||||
|
||||
// A concrete DeathTestFactory implementation for normal use.
|
||||
class DefaultDeathTestFactory : public DeathTestFactory {
|
||||
public:
|
||||
bool Create(const char* statement, Matcher<const std::string&> matcher,
|
||||
const char* file, int line, DeathTest** test) override;
|
||||
};
|
||||
|
||||
// Returns true if exit_status describes a process that was terminated
|
||||
// by a signal, or exited normally with a nonzero exit code.
|
||||
GTEST_API_ bool ExitedUnsuccessfully(int exit_status);
|
||||
|
||||
// A string passed to EXPECT_DEATH (etc.) is caught by one of these overloads
|
||||
// and interpreted as a regex (rather than an Eq matcher) for legacy
|
||||
// compatibility.
|
||||
inline Matcher<const ::std::string&> MakeDeathTestMatcher(
|
||||
::testing::internal::RE regex) {
|
||||
return ContainsRegex(regex.pattern());
|
||||
}
|
||||
inline Matcher<const ::std::string&> MakeDeathTestMatcher(const char* regex) {
|
||||
return ContainsRegex(regex);
|
||||
}
|
||||
inline Matcher<const ::std::string&> MakeDeathTestMatcher(
|
||||
const ::std::string& regex) {
|
||||
return ContainsRegex(regex);
|
||||
}
|
||||
|
||||
// If a Matcher<const ::std::string&> is passed to EXPECT_DEATH (etc.), it's
|
||||
// used directly.
|
||||
inline Matcher<const ::std::string&> MakeDeathTestMatcher(
|
||||
Matcher<const ::std::string&> matcher) {
|
||||
return matcher;
|
||||
}
|
||||
|
||||
// Traps C++ exceptions escaping statement and reports them as test
|
||||
// failures. Note that trapping SEH exceptions is not implemented here.
|
||||
# if GTEST_HAS_EXCEPTIONS
|
||||
# define GTEST_EXECUTE_DEATH_TEST_STATEMENT_(statement, death_test) \
|
||||
try { \
|
||||
GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
|
||||
} catch (const ::std::exception& gtest_exception) { \
|
||||
fprintf(\
|
||||
stderr, \
|
||||
"\n%s: Caught std::exception-derived exception escaping the " \
|
||||
"death test statement. Exception message: %s\n", \
|
||||
::testing::internal::FormatFileLocation(__FILE__, __LINE__).c_str(), \
|
||||
gtest_exception.what()); \
|
||||
fflush(stderr); \
|
||||
death_test->Abort(::testing::internal::DeathTest::TEST_THREW_EXCEPTION); \
|
||||
} catch (...) { \
|
||||
death_test->Abort(::testing::internal::DeathTest::TEST_THREW_EXCEPTION); \
|
||||
}
|
||||
|
||||
# else
|
||||
# define GTEST_EXECUTE_DEATH_TEST_STATEMENT_(statement, death_test) \
|
||||
GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement)
|
||||
|
||||
# endif
|
||||
|
||||
// This macro is for implementing ASSERT_DEATH*, EXPECT_DEATH*,
|
||||
// ASSERT_EXIT*, and EXPECT_EXIT*.
|
||||
#define GTEST_DEATH_TEST_(statement, predicate, regex_or_matcher, fail) \
|
||||
GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
|
||||
if (::testing::internal::AlwaysTrue()) { \
|
||||
::testing::internal::DeathTest* gtest_dt; \
|
||||
if (!::testing::internal::DeathTest::Create( \
|
||||
#statement, \
|
||||
::testing::internal::MakeDeathTestMatcher(regex_or_matcher), \
|
||||
__FILE__, __LINE__, >est_dt)) { \
|
||||
goto GTEST_CONCAT_TOKEN_(gtest_label_, __LINE__); \
|
||||
} \
|
||||
if (gtest_dt != nullptr) { \
|
||||
std::unique_ptr< ::testing::internal::DeathTest> gtest_dt_ptr(gtest_dt); \
|
||||
switch (gtest_dt->AssumeRole()) { \
|
||||
case ::testing::internal::DeathTest::OVERSEE_TEST: \
|
||||
if (!gtest_dt->Passed(predicate(gtest_dt->Wait()))) { \
|
||||
goto GTEST_CONCAT_TOKEN_(gtest_label_, __LINE__); \
|
||||
} \
|
||||
break; \
|
||||
case ::testing::internal::DeathTest::EXECUTE_TEST: { \
|
||||
::testing::internal::DeathTest::ReturnSentinel gtest_sentinel( \
|
||||
gtest_dt); \
|
||||
GTEST_EXECUTE_DEATH_TEST_STATEMENT_(statement, gtest_dt); \
|
||||
gtest_dt->Abort(::testing::internal::DeathTest::TEST_DID_NOT_DIE); \
|
||||
break; \
|
||||
} \
|
||||
default: \
|
||||
break; \
|
||||
} \
|
||||
} \
|
||||
} else \
|
||||
GTEST_CONCAT_TOKEN_(gtest_label_, __LINE__) \
|
||||
: fail(::testing::internal::DeathTest::LastMessage())
|
||||
// The symbol "fail" here expands to something into which a message
|
||||
// can be streamed.
|
||||
|
||||
// This macro is for implementing ASSERT/EXPECT_DEBUG_DEATH when compiled in
|
||||
// NDEBUG mode. In this case we need the statements to be executed and the macro
|
||||
// must accept a streamed message even though the message is never printed.
|
||||
// The regex object is not evaluated, but it is used to prevent "unused"
|
||||
// warnings and to avoid an expression that doesn't compile in debug mode.
|
||||
#define GTEST_EXECUTE_STATEMENT_(statement, regex_or_matcher) \
|
||||
GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
|
||||
if (::testing::internal::AlwaysTrue()) { \
|
||||
GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
|
||||
} else if (!::testing::internal::AlwaysTrue()) { \
|
||||
::testing::internal::MakeDeathTestMatcher(regex_or_matcher); \
|
||||
} else \
|
||||
::testing::Message()
|
||||
|
||||
// A class representing the parsed contents of the
|
||||
// --gtest_internal_run_death_test flag, as it existed when
|
||||
// RUN_ALL_TESTS was called.
|
||||
class InternalRunDeathTestFlag {
|
||||
public:
|
||||
InternalRunDeathTestFlag(const std::string& a_file,
|
||||
int a_line,
|
||||
int an_index,
|
||||
int a_write_fd)
|
||||
: file_(a_file), line_(a_line), index_(an_index),
|
||||
write_fd_(a_write_fd) {}
|
||||
|
||||
~InternalRunDeathTestFlag() {
|
||||
if (write_fd_ >= 0)
|
||||
posix::Close(write_fd_);
|
||||
}
|
||||
|
||||
const std::string& file() const { return file_; }
|
||||
int line() const { return line_; }
|
||||
int index() const { return index_; }
|
||||
int write_fd() const { return write_fd_; }
|
||||
|
||||
private:
|
||||
std::string file_;
|
||||
int line_;
|
||||
int index_;
|
||||
int write_fd_;
|
||||
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(InternalRunDeathTestFlag);
|
||||
};
|
||||
|
||||
// Returns a newly created InternalRunDeathTestFlag object with fields
|
||||
// initialized from the GTEST_FLAG(internal_run_death_test) flag if
|
||||
// the flag is specified; otherwise returns NULL.
|
||||
InternalRunDeathTestFlag* ParseInternalRunDeathTestFlag();
|
||||
|
||||
#endif // GTEST_HAS_DEATH_TEST
|
||||
|
||||
} // namespace internal
|
||||
} // namespace testing
|
||||
|
||||
#endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_DEATH_TEST_INTERNAL_H_
|
||||
@@ -1,211 +0,0 @@
|
||||
// Copyright 2008, Google Inc.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Google Test filepath utilities
|
||||
//
|
||||
// This header file declares classes and functions used internally by
|
||||
// Google Test. They are subject to change without notice.
|
||||
//
|
||||
// This file is #included in gtest/internal/gtest-internal.h.
|
||||
// Do not include this header file separately!
|
||||
|
||||
// GOOGLETEST_CM0001 DO NOT DELETE
|
||||
|
||||
#ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_FILEPATH_H_
|
||||
#define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_FILEPATH_H_
|
||||
|
||||
#include "gtest/internal/gtest-string.h"
|
||||
|
||||
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251 \
|
||||
/* class A needs to have dll-interface to be used by clients of class B */)
|
||||
|
||||
namespace testing {
|
||||
namespace internal {
|
||||
|
||||
// FilePath - a class for file and directory pathname manipulation which
|
||||
// handles platform-specific conventions (like the pathname separator).
|
||||
// Used for helper functions for naming files in a directory for xml output.
|
||||
// Except for Set methods, all methods are const or static, which provides an
|
||||
// "immutable value object" -- useful for peace of mind.
|
||||
// A FilePath with a value ending in a path separator ("like/this/") represents
|
||||
// a directory, otherwise it is assumed to represent a file. In either case,
|
||||
// it may or may not represent an actual file or directory in the file system.
|
||||
// Names are NOT checked for syntax correctness -- no checking for illegal
|
||||
// characters, malformed paths, etc.
|
||||
|
||||
class GTEST_API_ FilePath {
|
||||
public:
|
||||
FilePath() : pathname_("") { }
|
||||
FilePath(const FilePath& rhs) : pathname_(rhs.pathname_) { }
|
||||
|
||||
explicit FilePath(const std::string& pathname) : pathname_(pathname) {
|
||||
Normalize();
|
||||
}
|
||||
|
||||
FilePath& operator=(const FilePath& rhs) {
|
||||
Set(rhs);
|
||||
return *this;
|
||||
}
|
||||
|
||||
void Set(const FilePath& rhs) {
|
||||
pathname_ = rhs.pathname_;
|
||||
}
|
||||
|
||||
const std::string& string() const { return pathname_; }
|
||||
const char* c_str() const { return pathname_.c_str(); }
|
||||
|
||||
// Returns the current working directory, or "" if unsuccessful.
|
||||
static FilePath GetCurrentDir();
|
||||
|
||||
// Given directory = "dir", base_name = "test", number = 0,
|
||||
// extension = "xml", returns "dir/test.xml". If number is greater
|
||||
// than zero (e.g., 12), returns "dir/test_12.xml".
|
||||
// On Windows platform, uses \ as the separator rather than /.
|
||||
static FilePath MakeFileName(const FilePath& directory,
|
||||
const FilePath& base_name,
|
||||
int number,
|
||||
const char* extension);
|
||||
|
||||
// Given directory = "dir", relative_path = "test.xml",
|
||||
// returns "dir/test.xml".
|
||||
// On Windows, uses \ as the separator rather than /.
|
||||
static FilePath ConcatPaths(const FilePath& directory,
|
||||
const FilePath& relative_path);
|
||||
|
||||
// Returns a pathname for a file that does not currently exist. The pathname
|
||||
// will be directory/base_name.extension or
|
||||
// directory/base_name_<number>.extension if directory/base_name.extension
|
||||
// already exists. The number will be incremented until a pathname is found
|
||||
// that does not already exist.
|
||||
// Examples: 'dir/foo_test.xml' or 'dir/foo_test_1.xml'.
|
||||
// There could be a race condition if two or more processes are calling this
|
||||
// function at the same time -- they could both pick the same filename.
|
||||
static FilePath GenerateUniqueFileName(const FilePath& directory,
|
||||
const FilePath& base_name,
|
||||
const char* extension);
|
||||
|
||||
// Returns true if and only if the path is "".
|
||||
bool IsEmpty() const { return pathname_.empty(); }
|
||||
|
||||
// If input name has a trailing separator character, removes it and returns
|
||||
// the name, otherwise return the name string unmodified.
|
||||
// On Windows platform, uses \ as the separator, other platforms use /.
|
||||
FilePath RemoveTrailingPathSeparator() const;
|
||||
|
||||
// Returns a copy of the FilePath with the directory part removed.
|
||||
// Example: FilePath("path/to/file").RemoveDirectoryName() returns
|
||||
// FilePath("file"). If there is no directory part ("just_a_file"), it returns
|
||||
// the FilePath unmodified. If there is no file part ("just_a_dir/") it
|
||||
// returns an empty FilePath ("").
|
||||
// On Windows platform, '\' is the path separator, otherwise it is '/'.
|
||||
FilePath RemoveDirectoryName() const;
|
||||
|
||||
// RemoveFileName returns the directory path with the filename removed.
|
||||
// Example: FilePath("path/to/file").RemoveFileName() returns "path/to/".
|
||||
// If the FilePath is "a_file" or "/a_file", RemoveFileName returns
|
||||
// FilePath("./") or, on Windows, FilePath(".\\"). If the filepath does
|
||||
// not have a file, like "just/a/dir/", it returns the FilePath unmodified.
|
||||
// On Windows platform, '\' is the path separator, otherwise it is '/'.
|
||||
FilePath RemoveFileName() const;
|
||||
|
||||
// Returns a copy of the FilePath with the case-insensitive extension removed.
|
||||
// Example: FilePath("dir/file.exe").RemoveExtension("EXE") returns
|
||||
// FilePath("dir/file"). If a case-insensitive extension is not
|
||||
// found, returns a copy of the original FilePath.
|
||||
FilePath RemoveExtension(const char* extension) const;
|
||||
|
||||
// Creates directories so that path exists. Returns true if successful or if
|
||||
// the directories already exist; returns false if unable to create
|
||||
// directories for any reason. Will also return false if the FilePath does
|
||||
// not represent a directory (that is, it doesn't end with a path separator).
|
||||
bool CreateDirectoriesRecursively() const;
|
||||
|
||||
// Create the directory so that path exists. Returns true if successful or
|
||||
// if the directory already exists; returns false if unable to create the
|
||||
// directory for any reason, including if the parent directory does not
|
||||
// exist. Not named "CreateDirectory" because that's a macro on Windows.
|
||||
bool CreateFolder() const;
|
||||
|
||||
// Returns true if FilePath describes something in the file-system,
|
||||
// either a file, directory, or whatever, and that something exists.
|
||||
bool FileOrDirectoryExists() const;
|
||||
|
||||
// Returns true if pathname describes a directory in the file-system
|
||||
// that exists.
|
||||
bool DirectoryExists() const;
|
||||
|
||||
// Returns true if FilePath ends with a path separator, which indicates that
|
||||
// it is intended to represent a directory. Returns false otherwise.
|
||||
// This does NOT check that a directory (or file) actually exists.
|
||||
bool IsDirectory() const;
|
||||
|
||||
// Returns true if pathname describes a root directory. (Windows has one
|
||||
// root directory per disk drive.)
|
||||
bool IsRootDirectory() const;
|
||||
|
||||
// Returns true if pathname describes an absolute path.
|
||||
bool IsAbsolutePath() const;
|
||||
|
||||
private:
|
||||
// Replaces multiple consecutive separators with a single separator.
|
||||
// For example, "bar///foo" becomes "bar/foo". Does not eliminate other
|
||||
// redundancies that might be in a pathname involving "." or "..".
|
||||
//
|
||||
// A pathname with multiple consecutive separators may occur either through
|
||||
// user error or as a result of some scripts or APIs that generate a pathname
|
||||
// with a trailing separator. On other platforms the same API or script
|
||||
// may NOT generate a pathname with a trailing "/". Then elsewhere that
|
||||
// pathname may have another "/" and pathname components added to it,
|
||||
// without checking for the separator already being there.
|
||||
// The script language and operating system may allow paths like "foo//bar"
|
||||
// but some of the functions in FilePath will not handle that correctly. In
|
||||
// particular, RemoveTrailingPathSeparator() only removes one separator, and
|
||||
// it is called in CreateDirectoriesRecursively() assuming that it will change
|
||||
// a pathname from directory syntax (trailing separator) to filename syntax.
|
||||
//
|
||||
// On Windows this method also replaces the alternate path separator '/' with
|
||||
// the primary path separator '\\', so that for example "bar\\/\\foo" becomes
|
||||
// "bar\\foo".
|
||||
|
||||
void Normalize();
|
||||
|
||||
// Returns a pointer to the last occurence of a valid path separator in
|
||||
// the FilePath. On Windows, for example, both '/' and '\' are valid path
|
||||
// separators. Returns NULL if no path separator was found.
|
||||
const char* FindLastPathSeparator() const;
|
||||
|
||||
std::string pathname_;
|
||||
}; // class FilePath
|
||||
|
||||
} // namespace internal
|
||||
} // namespace testing
|
||||
|
||||
GTEST_DISABLE_MSC_WARNINGS_POP_() // 4251
|
||||
|
||||
#endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_FILEPATH_H_
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,883 +0,0 @@
|
||||
// Copyright 2008 Google Inc.
|
||||
// All Rights Reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
|
||||
// Type and function utilities for implementing parameterized tests.
|
||||
|
||||
// GOOGLETEST_CM0001 DO NOT DELETE
|
||||
|
||||
#ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PARAM_UTIL_H_
|
||||
#define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PARAM_UTIL_H_
|
||||
|
||||
#include <ctype.h>
|
||||
|
||||
#include <cassert>
|
||||
#include <iterator>
|
||||
#include <memory>
|
||||
#include <set>
|
||||
#include <tuple>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "gtest/internal/gtest-internal.h"
|
||||
#include "gtest/internal/gtest-port.h"
|
||||
#include "gtest/gtest-printers.h"
|
||||
|
||||
namespace testing {
|
||||
// Input to a parameterized test name generator, describing a test parameter.
|
||||
// Consists of the parameter value and the integer parameter index.
|
||||
template <class ParamType>
|
||||
struct TestParamInfo {
|
||||
TestParamInfo(const ParamType& a_param, size_t an_index) :
|
||||
param(a_param),
|
||||
index(an_index) {}
|
||||
ParamType param;
|
||||
size_t index;
|
||||
};
|
||||
|
||||
// A builtin parameterized test name generator which returns the result of
|
||||
// testing::PrintToString.
|
||||
struct PrintToStringParamName {
|
||||
template <class ParamType>
|
||||
std::string operator()(const TestParamInfo<ParamType>& info) const {
|
||||
return PrintToString(info.param);
|
||||
}
|
||||
};
|
||||
|
||||
namespace internal {
|
||||
|
||||
// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
|
||||
// Utility Functions
|
||||
|
||||
// Outputs a message explaining invalid registration of different
|
||||
// fixture class for the same test suite. This may happen when
|
||||
// TEST_P macro is used to define two tests with the same name
|
||||
// but in different namespaces.
|
||||
GTEST_API_ void ReportInvalidTestSuiteType(const char* test_suite_name,
|
||||
CodeLocation code_location);
|
||||
|
||||
template <typename> class ParamGeneratorInterface;
|
||||
template <typename> class ParamGenerator;
|
||||
|
||||
// Interface for iterating over elements provided by an implementation
|
||||
// of ParamGeneratorInterface<T>.
|
||||
template <typename T>
|
||||
class ParamIteratorInterface {
|
||||
public:
|
||||
virtual ~ParamIteratorInterface() {}
|
||||
// A pointer to the base generator instance.
|
||||
// Used only for the purposes of iterator comparison
|
||||
// to make sure that two iterators belong to the same generator.
|
||||
virtual const ParamGeneratorInterface<T>* BaseGenerator() const = 0;
|
||||
// Advances iterator to point to the next element
|
||||
// provided by the generator. The caller is responsible
|
||||
// for not calling Advance() on an iterator equal to
|
||||
// BaseGenerator()->End().
|
||||
virtual void Advance() = 0;
|
||||
// Clones the iterator object. Used for implementing copy semantics
|
||||
// of ParamIterator<T>.
|
||||
virtual ParamIteratorInterface* Clone() const = 0;
|
||||
// Dereferences the current iterator and provides (read-only) access
|
||||
// to the pointed value. It is the caller's responsibility not to call
|
||||
// Current() on an iterator equal to BaseGenerator()->End().
|
||||
// Used for implementing ParamGenerator<T>::operator*().
|
||||
virtual const T* Current() const = 0;
|
||||
// Determines whether the given iterator and other point to the same
|
||||
// element in the sequence generated by the generator.
|
||||
// Used for implementing ParamGenerator<T>::operator==().
|
||||
virtual bool Equals(const ParamIteratorInterface& other) const = 0;
|
||||
};
|
||||
|
||||
// Class iterating over elements provided by an implementation of
|
||||
// ParamGeneratorInterface<T>. It wraps ParamIteratorInterface<T>
|
||||
// and implements the const forward iterator concept.
|
||||
template <typename T>
|
||||
class ParamIterator {
|
||||
public:
|
||||
typedef T value_type;
|
||||
typedef const T& reference;
|
||||
typedef ptrdiff_t difference_type;
|
||||
|
||||
// ParamIterator assumes ownership of the impl_ pointer.
|
||||
ParamIterator(const ParamIterator& other) : impl_(other.impl_->Clone()) {}
|
||||
ParamIterator& operator=(const ParamIterator& other) {
|
||||
if (this != &other)
|
||||
impl_.reset(other.impl_->Clone());
|
||||
return *this;
|
||||
}
|
||||
|
||||
const T& operator*() const { return *impl_->Current(); }
|
||||
const T* operator->() const { return impl_->Current(); }
|
||||
// Prefix version of operator++.
|
||||
ParamIterator& operator++() {
|
||||
impl_->Advance();
|
||||
return *this;
|
||||
}
|
||||
// Postfix version of operator++.
|
||||
ParamIterator operator++(int /*unused*/) {
|
||||
ParamIteratorInterface<T>* clone = impl_->Clone();
|
||||
impl_->Advance();
|
||||
return ParamIterator(clone);
|
||||
}
|
||||
bool operator==(const ParamIterator& other) const {
|
||||
return impl_.get() == other.impl_.get() || impl_->Equals(*other.impl_);
|
||||
}
|
||||
bool operator!=(const ParamIterator& other) const {
|
||||
return !(*this == other);
|
||||
}
|
||||
|
||||
private:
|
||||
friend class ParamGenerator<T>;
|
||||
explicit ParamIterator(ParamIteratorInterface<T>* impl) : impl_(impl) {}
|
||||
std::unique_ptr<ParamIteratorInterface<T> > impl_;
|
||||
};
|
||||
|
||||
// ParamGeneratorInterface<T> is the binary interface to access generators
|
||||
// defined in other translation units.
|
||||
template <typename T>
|
||||
class ParamGeneratorInterface {
|
||||
public:
|
||||
typedef T ParamType;
|
||||
|
||||
virtual ~ParamGeneratorInterface() {}
|
||||
|
||||
// Generator interface definition
|
||||
virtual ParamIteratorInterface<T>* Begin() const = 0;
|
||||
virtual ParamIteratorInterface<T>* End() const = 0;
|
||||
};
|
||||
|
||||
// Wraps ParamGeneratorInterface<T> and provides general generator syntax
|
||||
// compatible with the STL Container concept.
|
||||
// This class implements copy initialization semantics and the contained
|
||||
// ParamGeneratorInterface<T> instance is shared among all copies
|
||||
// of the original object. This is possible because that instance is immutable.
|
||||
template<typename T>
|
||||
class ParamGenerator {
|
||||
public:
|
||||
typedef ParamIterator<T> iterator;
|
||||
|
||||
explicit ParamGenerator(ParamGeneratorInterface<T>* impl) : impl_(impl) {}
|
||||
ParamGenerator(const ParamGenerator& other) : impl_(other.impl_) {}
|
||||
|
||||
ParamGenerator& operator=(const ParamGenerator& other) {
|
||||
impl_ = other.impl_;
|
||||
return *this;
|
||||
}
|
||||
|
||||
iterator begin() const { return iterator(impl_->Begin()); }
|
||||
iterator end() const { return iterator(impl_->End()); }
|
||||
|
||||
private:
|
||||
std::shared_ptr<const ParamGeneratorInterface<T> > impl_;
|
||||
};
|
||||
|
||||
// Generates values from a range of two comparable values. Can be used to
|
||||
// generate sequences of user-defined types that implement operator+() and
|
||||
// operator<().
|
||||
// This class is used in the Range() function.
|
||||
template <typename T, typename IncrementT>
|
||||
class RangeGenerator : public ParamGeneratorInterface<T> {
|
||||
public:
|
||||
RangeGenerator(T begin, T end, IncrementT step)
|
||||
: begin_(begin), end_(end),
|
||||
step_(step), end_index_(CalculateEndIndex(begin, end, step)) {}
|
||||
~RangeGenerator() override {}
|
||||
|
||||
ParamIteratorInterface<T>* Begin() const override {
|
||||
return new Iterator(this, begin_, 0, step_);
|
||||
}
|
||||
ParamIteratorInterface<T>* End() const override {
|
||||
return new Iterator(this, end_, end_index_, step_);
|
||||
}
|
||||
|
||||
private:
|
||||
class Iterator : public ParamIteratorInterface<T> {
|
||||
public:
|
||||
Iterator(const ParamGeneratorInterface<T>* base, T value, int index,
|
||||
IncrementT step)
|
||||
: base_(base), value_(value), index_(index), step_(step) {}
|
||||
~Iterator() override {}
|
||||
|
||||
const ParamGeneratorInterface<T>* BaseGenerator() const override {
|
||||
return base_;
|
||||
}
|
||||
void Advance() override {
|
||||
value_ = static_cast<T>(value_ + step_);
|
||||
index_++;
|
||||
}
|
||||
ParamIteratorInterface<T>* Clone() const override {
|
||||
return new Iterator(*this);
|
||||
}
|
||||
const T* Current() const override { return &value_; }
|
||||
bool Equals(const ParamIteratorInterface<T>& other) const override {
|
||||
// Having the same base generator guarantees that the other
|
||||
// iterator is of the same type and we can downcast.
|
||||
GTEST_CHECK_(BaseGenerator() == other.BaseGenerator())
|
||||
<< "The program attempted to compare iterators "
|
||||
<< "from different generators." << std::endl;
|
||||
const int other_index =
|
||||
CheckedDowncastToActualType<const Iterator>(&other)->index_;
|
||||
return index_ == other_index;
|
||||
}
|
||||
|
||||
private:
|
||||
Iterator(const Iterator& other)
|
||||
: ParamIteratorInterface<T>(),
|
||||
base_(other.base_), value_(other.value_), index_(other.index_),
|
||||
step_(other.step_) {}
|
||||
|
||||
// No implementation - assignment is unsupported.
|
||||
void operator=(const Iterator& other);
|
||||
|
||||
const ParamGeneratorInterface<T>* const base_;
|
||||
T value_;
|
||||
int index_;
|
||||
const IncrementT step_;
|
||||
}; // class RangeGenerator::Iterator
|
||||
|
||||
static int CalculateEndIndex(const T& begin,
|
||||
const T& end,
|
||||
const IncrementT& step) {
|
||||
int end_index = 0;
|
||||
for (T i = begin; i < end; i = static_cast<T>(i + step))
|
||||
end_index++;
|
||||
return end_index;
|
||||
}
|
||||
|
||||
// No implementation - assignment is unsupported.
|
||||
void operator=(const RangeGenerator& other);
|
||||
|
||||
const T begin_;
|
||||
const T end_;
|
||||
const IncrementT step_;
|
||||
// The index for the end() iterator. All the elements in the generated
|
||||
// sequence are indexed (0-based) to aid iterator comparison.
|
||||
const int end_index_;
|
||||
}; // class RangeGenerator
|
||||
|
||||
|
||||
// Generates values from a pair of STL-style iterators. Used in the
|
||||
// ValuesIn() function. The elements are copied from the source range
|
||||
// since the source can be located on the stack, and the generator
|
||||
// is likely to persist beyond that stack frame.
|
||||
template <typename T>
|
||||
class ValuesInIteratorRangeGenerator : public ParamGeneratorInterface<T> {
|
||||
public:
|
||||
template <typename ForwardIterator>
|
||||
ValuesInIteratorRangeGenerator(ForwardIterator begin, ForwardIterator end)
|
||||
: container_(begin, end) {}
|
||||
~ValuesInIteratorRangeGenerator() override {}
|
||||
|
||||
ParamIteratorInterface<T>* Begin() const override {
|
||||
return new Iterator(this, container_.begin());
|
||||
}
|
||||
ParamIteratorInterface<T>* End() const override {
|
||||
return new Iterator(this, container_.end());
|
||||
}
|
||||
|
||||
private:
|
||||
typedef typename ::std::vector<T> ContainerType;
|
||||
|
||||
class Iterator : public ParamIteratorInterface<T> {
|
||||
public:
|
||||
Iterator(const ParamGeneratorInterface<T>* base,
|
||||
typename ContainerType::const_iterator iterator)
|
||||
: base_(base), iterator_(iterator) {}
|
||||
~Iterator() override {}
|
||||
|
||||
const ParamGeneratorInterface<T>* BaseGenerator() const override {
|
||||
return base_;
|
||||
}
|
||||
void Advance() override {
|
||||
++iterator_;
|
||||
value_.reset();
|
||||
}
|
||||
ParamIteratorInterface<T>* Clone() const override {
|
||||
return new Iterator(*this);
|
||||
}
|
||||
// We need to use cached value referenced by iterator_ because *iterator_
|
||||
// can return a temporary object (and of type other then T), so just
|
||||
// having "return &*iterator_;" doesn't work.
|
||||
// value_ is updated here and not in Advance() because Advance()
|
||||
// can advance iterator_ beyond the end of the range, and we cannot
|
||||
// detect that fact. The client code, on the other hand, is
|
||||
// responsible for not calling Current() on an out-of-range iterator.
|
||||
const T* Current() const override {
|
||||
if (value_.get() == nullptr) value_.reset(new T(*iterator_));
|
||||
return value_.get();
|
||||
}
|
||||
bool Equals(const ParamIteratorInterface<T>& other) const override {
|
||||
// Having the same base generator guarantees that the other
|
||||
// iterator is of the same type and we can downcast.
|
||||
GTEST_CHECK_(BaseGenerator() == other.BaseGenerator())
|
||||
<< "The program attempted to compare iterators "
|
||||
<< "from different generators." << std::endl;
|
||||
return iterator_ ==
|
||||
CheckedDowncastToActualType<const Iterator>(&other)->iterator_;
|
||||
}
|
||||
|
||||
private:
|
||||
Iterator(const Iterator& other)
|
||||
// The explicit constructor call suppresses a false warning
|
||||
// emitted by gcc when supplied with the -Wextra option.
|
||||
: ParamIteratorInterface<T>(),
|
||||
base_(other.base_),
|
||||
iterator_(other.iterator_) {}
|
||||
|
||||
const ParamGeneratorInterface<T>* const base_;
|
||||
typename ContainerType::const_iterator iterator_;
|
||||
// A cached value of *iterator_. We keep it here to allow access by
|
||||
// pointer in the wrapping iterator's operator->().
|
||||
// value_ needs to be mutable to be accessed in Current().
|
||||
// Use of std::unique_ptr helps manage cached value's lifetime,
|
||||
// which is bound by the lifespan of the iterator itself.
|
||||
mutable std::unique_ptr<const T> value_;
|
||||
}; // class ValuesInIteratorRangeGenerator::Iterator
|
||||
|
||||
// No implementation - assignment is unsupported.
|
||||
void operator=(const ValuesInIteratorRangeGenerator& other);
|
||||
|
||||
const ContainerType container_;
|
||||
}; // class ValuesInIteratorRangeGenerator
|
||||
|
||||
// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
|
||||
//
|
||||
// Default parameterized test name generator, returns a string containing the
|
||||
// integer test parameter index.
|
||||
template <class ParamType>
|
||||
std::string DefaultParamName(const TestParamInfo<ParamType>& info) {
|
||||
Message name_stream;
|
||||
name_stream << info.index;
|
||||
return name_stream.GetString();
|
||||
}
|
||||
|
||||
template <typename T = int>
|
||||
void TestNotEmpty() {
|
||||
static_assert(sizeof(T) == 0, "Empty arguments are not allowed.");
|
||||
}
|
||||
template <typename T = int>
|
||||
void TestNotEmpty(const T&) {}
|
||||
|
||||
// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
|
||||
//
|
||||
// Stores a parameter value and later creates tests parameterized with that
|
||||
// value.
|
||||
template <class TestClass>
|
||||
class ParameterizedTestFactory : public TestFactoryBase {
|
||||
public:
|
||||
typedef typename TestClass::ParamType ParamType;
|
||||
explicit ParameterizedTestFactory(ParamType parameter) :
|
||||
parameter_(parameter) {}
|
||||
Test* CreateTest() override {
|
||||
TestClass::SetParam(¶meter_);
|
||||
return new TestClass();
|
||||
}
|
||||
|
||||
private:
|
||||
const ParamType parameter_;
|
||||
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(ParameterizedTestFactory);
|
||||
};
|
||||
|
||||
// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
|
||||
//
|
||||
// TestMetaFactoryBase is a base class for meta-factories that create
|
||||
// test factories for passing into MakeAndRegisterTestInfo function.
|
||||
template <class ParamType>
|
||||
class TestMetaFactoryBase {
|
||||
public:
|
||||
virtual ~TestMetaFactoryBase() {}
|
||||
|
||||
virtual TestFactoryBase* CreateTestFactory(ParamType parameter) = 0;
|
||||
};
|
||||
|
||||
// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
|
||||
//
|
||||
// TestMetaFactory creates test factories for passing into
|
||||
// MakeAndRegisterTestInfo function. Since MakeAndRegisterTestInfo receives
|
||||
// ownership of test factory pointer, same factory object cannot be passed
|
||||
// into that method twice. But ParameterizedTestSuiteInfo is going to call
|
||||
// it for each Test/Parameter value combination. Thus it needs meta factory
|
||||
// creator class.
|
||||
template <class TestSuite>
|
||||
class TestMetaFactory
|
||||
: public TestMetaFactoryBase<typename TestSuite::ParamType> {
|
||||
public:
|
||||
using ParamType = typename TestSuite::ParamType;
|
||||
|
||||
TestMetaFactory() {}
|
||||
|
||||
TestFactoryBase* CreateTestFactory(ParamType parameter) override {
|
||||
return new ParameterizedTestFactory<TestSuite>(parameter);
|
||||
}
|
||||
|
||||
private:
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(TestMetaFactory);
|
||||
};
|
||||
|
||||
// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
|
||||
//
|
||||
// ParameterizedTestSuiteInfoBase is a generic interface
|
||||
// to ParameterizedTestSuiteInfo classes. ParameterizedTestSuiteInfoBase
|
||||
// accumulates test information provided by TEST_P macro invocations
|
||||
// and generators provided by INSTANTIATE_TEST_SUITE_P macro invocations
|
||||
// and uses that information to register all resulting test instances
|
||||
// in RegisterTests method. The ParameterizeTestSuiteRegistry class holds
|
||||
// a collection of pointers to the ParameterizedTestSuiteInfo objects
|
||||
// and calls RegisterTests() on each of them when asked.
|
||||
class ParameterizedTestSuiteInfoBase {
|
||||
public:
|
||||
virtual ~ParameterizedTestSuiteInfoBase() {}
|
||||
|
||||
// Base part of test suite name for display purposes.
|
||||
virtual const std::string& GetTestSuiteName() const = 0;
|
||||
// Test case id to verify identity.
|
||||
virtual TypeId GetTestSuiteTypeId() const = 0;
|
||||
// UnitTest class invokes this method to register tests in this
|
||||
// test suite right before running them in RUN_ALL_TESTS macro.
|
||||
// This method should not be called more than once on any single
|
||||
// instance of a ParameterizedTestSuiteInfoBase derived class.
|
||||
virtual void RegisterTests() = 0;
|
||||
|
||||
protected:
|
||||
ParameterizedTestSuiteInfoBase() {}
|
||||
|
||||
private:
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(ParameterizedTestSuiteInfoBase);
|
||||
};
|
||||
|
||||
// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
|
||||
//
|
||||
// ParameterizedTestSuiteInfo accumulates tests obtained from TEST_P
|
||||
// macro invocations for a particular test suite and generators
|
||||
// obtained from INSTANTIATE_TEST_SUITE_P macro invocations for that
|
||||
// test suite. It registers tests with all values generated by all
|
||||
// generators when asked.
|
||||
template <class TestSuite>
|
||||
class ParameterizedTestSuiteInfo : public ParameterizedTestSuiteInfoBase {
|
||||
public:
|
||||
// ParamType and GeneratorCreationFunc are private types but are required
|
||||
// for declarations of public methods AddTestPattern() and
|
||||
// AddTestSuiteInstantiation().
|
||||
using ParamType = typename TestSuite::ParamType;
|
||||
// A function that returns an instance of appropriate generator type.
|
||||
typedef ParamGenerator<ParamType>(GeneratorCreationFunc)();
|
||||
using ParamNameGeneratorFunc = std::string(const TestParamInfo<ParamType>&);
|
||||
|
||||
explicit ParameterizedTestSuiteInfo(const char* name,
|
||||
CodeLocation code_location)
|
||||
: test_suite_name_(name), code_location_(code_location) {}
|
||||
|
||||
// Test case base name for display purposes.
|
||||
const std::string& GetTestSuiteName() const override {
|
||||
return test_suite_name_;
|
||||
}
|
||||
// Test case id to verify identity.
|
||||
TypeId GetTestSuiteTypeId() const override { return GetTypeId<TestSuite>(); }
|
||||
// TEST_P macro uses AddTestPattern() to record information
|
||||
// about a single test in a LocalTestInfo structure.
|
||||
// test_suite_name is the base name of the test suite (without invocation
|
||||
// prefix). test_base_name is the name of an individual test without
|
||||
// parameter index. For the test SequenceA/FooTest.DoBar/1 FooTest is
|
||||
// test suite base name and DoBar is test base name.
|
||||
void AddTestPattern(const char* test_suite_name, const char* test_base_name,
|
||||
TestMetaFactoryBase<ParamType>* meta_factory) {
|
||||
tests_.push_back(std::shared_ptr<TestInfo>(
|
||||
new TestInfo(test_suite_name, test_base_name, meta_factory)));
|
||||
}
|
||||
// INSTANTIATE_TEST_SUITE_P macro uses AddGenerator() to record information
|
||||
// about a generator.
|
||||
int AddTestSuiteInstantiation(const std::string& instantiation_name,
|
||||
GeneratorCreationFunc* func,
|
||||
ParamNameGeneratorFunc* name_func,
|
||||
const char* file, int line) {
|
||||
instantiations_.push_back(
|
||||
InstantiationInfo(instantiation_name, func, name_func, file, line));
|
||||
return 0; // Return value used only to run this method in namespace scope.
|
||||
}
|
||||
// UnitTest class invokes this method to register tests in this test suite
|
||||
// test suites right before running tests in RUN_ALL_TESTS macro.
|
||||
// This method should not be called more than once on any single
|
||||
// instance of a ParameterizedTestSuiteInfoBase derived class.
|
||||
// UnitTest has a guard to prevent from calling this method more than once.
|
||||
void RegisterTests() override {
|
||||
for (typename TestInfoContainer::iterator test_it = tests_.begin();
|
||||
test_it != tests_.end(); ++test_it) {
|
||||
std::shared_ptr<TestInfo> test_info = *test_it;
|
||||
for (typename InstantiationContainer::iterator gen_it =
|
||||
instantiations_.begin(); gen_it != instantiations_.end();
|
||||
++gen_it) {
|
||||
const std::string& instantiation_name = gen_it->name;
|
||||
ParamGenerator<ParamType> generator((*gen_it->generator)());
|
||||
ParamNameGeneratorFunc* name_func = gen_it->name_func;
|
||||
const char* file = gen_it->file;
|
||||
int line = gen_it->line;
|
||||
|
||||
std::string test_suite_name;
|
||||
if ( !instantiation_name.empty() )
|
||||
test_suite_name = instantiation_name + "/";
|
||||
test_suite_name += test_info->test_suite_base_name;
|
||||
|
||||
size_t i = 0;
|
||||
std::set<std::string> test_param_names;
|
||||
for (typename ParamGenerator<ParamType>::iterator param_it =
|
||||
generator.begin();
|
||||
param_it != generator.end(); ++param_it, ++i) {
|
||||
Message test_name_stream;
|
||||
|
||||
std::string param_name = name_func(
|
||||
TestParamInfo<ParamType>(*param_it, i));
|
||||
|
||||
GTEST_CHECK_(IsValidParamName(param_name))
|
||||
<< "Parameterized test name '" << param_name
|
||||
<< "' is invalid, in " << file
|
||||
<< " line " << line << std::endl;
|
||||
|
||||
GTEST_CHECK_(test_param_names.count(param_name) == 0)
|
||||
<< "Duplicate parameterized test name '" << param_name
|
||||
<< "', in " << file << " line " << line << std::endl;
|
||||
|
||||
test_param_names.insert(param_name);
|
||||
|
||||
if (!test_info->test_base_name.empty()) {
|
||||
test_name_stream << test_info->test_base_name << "/";
|
||||
}
|
||||
test_name_stream << param_name;
|
||||
MakeAndRegisterTestInfo(
|
||||
test_suite_name.c_str(), test_name_stream.GetString().c_str(),
|
||||
nullptr, // No type parameter.
|
||||
PrintToString(*param_it).c_str(), code_location_,
|
||||
GetTestSuiteTypeId(),
|
||||
SuiteApiResolver<TestSuite>::GetSetUpCaseOrSuite(file, line),
|
||||
SuiteApiResolver<TestSuite>::GetTearDownCaseOrSuite(file, line),
|
||||
test_info->test_meta_factory->CreateTestFactory(*param_it));
|
||||
} // for param_it
|
||||
} // for gen_it
|
||||
} // for test_it
|
||||
} // RegisterTests
|
||||
|
||||
private:
|
||||
// LocalTestInfo structure keeps information about a single test registered
|
||||
// with TEST_P macro.
|
||||
struct TestInfo {
|
||||
TestInfo(const char* a_test_suite_base_name, const char* a_test_base_name,
|
||||
TestMetaFactoryBase<ParamType>* a_test_meta_factory)
|
||||
: test_suite_base_name(a_test_suite_base_name),
|
||||
test_base_name(a_test_base_name),
|
||||
test_meta_factory(a_test_meta_factory) {}
|
||||
|
||||
const std::string test_suite_base_name;
|
||||
const std::string test_base_name;
|
||||
const std::unique_ptr<TestMetaFactoryBase<ParamType> > test_meta_factory;
|
||||
};
|
||||
using TestInfoContainer = ::std::vector<std::shared_ptr<TestInfo> >;
|
||||
// Records data received from INSTANTIATE_TEST_SUITE_P macros:
|
||||
// <Instantiation name, Sequence generator creation function,
|
||||
// Name generator function, Source file, Source line>
|
||||
struct InstantiationInfo {
|
||||
InstantiationInfo(const std::string &name_in,
|
||||
GeneratorCreationFunc* generator_in,
|
||||
ParamNameGeneratorFunc* name_func_in,
|
||||
const char* file_in,
|
||||
int line_in)
|
||||
: name(name_in),
|
||||
generator(generator_in),
|
||||
name_func(name_func_in),
|
||||
file(file_in),
|
||||
line(line_in) {}
|
||||
|
||||
std::string name;
|
||||
GeneratorCreationFunc* generator;
|
||||
ParamNameGeneratorFunc* name_func;
|
||||
const char* file;
|
||||
int line;
|
||||
};
|
||||
typedef ::std::vector<InstantiationInfo> InstantiationContainer;
|
||||
|
||||
static bool IsValidParamName(const std::string& name) {
|
||||
// Check for empty string
|
||||
if (name.empty())
|
||||
return false;
|
||||
|
||||
// Check for invalid characters
|
||||
for (std::string::size_type index = 0; index < name.size(); ++index) {
|
||||
if (!isalnum(name[index]) && name[index] != '_')
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
const std::string test_suite_name_;
|
||||
CodeLocation code_location_;
|
||||
TestInfoContainer tests_;
|
||||
InstantiationContainer instantiations_;
|
||||
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(ParameterizedTestSuiteInfo);
|
||||
}; // class ParameterizedTestSuiteInfo
|
||||
|
||||
// Legacy API is deprecated but still available
|
||||
#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
|
||||
template <class TestCase>
|
||||
using ParameterizedTestCaseInfo = ParameterizedTestSuiteInfo<TestCase>;
|
||||
#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
|
||||
|
||||
// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
|
||||
//
|
||||
// ParameterizedTestSuiteRegistry contains a map of
|
||||
// ParameterizedTestSuiteInfoBase classes accessed by test suite names. TEST_P
|
||||
// and INSTANTIATE_TEST_SUITE_P macros use it to locate their corresponding
|
||||
// ParameterizedTestSuiteInfo descriptors.
|
||||
class ParameterizedTestSuiteRegistry {
|
||||
public:
|
||||
ParameterizedTestSuiteRegistry() {}
|
||||
~ParameterizedTestSuiteRegistry() {
|
||||
for (auto& test_suite_info : test_suite_infos_) {
|
||||
delete test_suite_info;
|
||||
}
|
||||
}
|
||||
|
||||
// Looks up or creates and returns a structure containing information about
|
||||
// tests and instantiations of a particular test suite.
|
||||
template <class TestSuite>
|
||||
ParameterizedTestSuiteInfo<TestSuite>* GetTestSuitePatternHolder(
|
||||
const char* test_suite_name, CodeLocation code_location) {
|
||||
ParameterizedTestSuiteInfo<TestSuite>* typed_test_info = nullptr;
|
||||
for (auto& test_suite_info : test_suite_infos_) {
|
||||
if (test_suite_info->GetTestSuiteName() == test_suite_name) {
|
||||
if (test_suite_info->GetTestSuiteTypeId() != GetTypeId<TestSuite>()) {
|
||||
// Complain about incorrect usage of Google Test facilities
|
||||
// and terminate the program since we cannot guaranty correct
|
||||
// test suite setup and tear-down in this case.
|
||||
ReportInvalidTestSuiteType(test_suite_name, code_location);
|
||||
posix::Abort();
|
||||
} else {
|
||||
// At this point we are sure that the object we found is of the same
|
||||
// type we are looking for, so we downcast it to that type
|
||||
// without further checks.
|
||||
typed_test_info = CheckedDowncastToActualType<
|
||||
ParameterizedTestSuiteInfo<TestSuite> >(test_suite_info);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (typed_test_info == nullptr) {
|
||||
typed_test_info = new ParameterizedTestSuiteInfo<TestSuite>(
|
||||
test_suite_name, code_location);
|
||||
test_suite_infos_.push_back(typed_test_info);
|
||||
}
|
||||
return typed_test_info;
|
||||
}
|
||||
void RegisterTests() {
|
||||
for (auto& test_suite_info : test_suite_infos_) {
|
||||
test_suite_info->RegisterTests();
|
||||
}
|
||||
}
|
||||
// Legacy API is deprecated but still available
|
||||
#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
|
||||
template <class TestCase>
|
||||
ParameterizedTestCaseInfo<TestCase>* GetTestCasePatternHolder(
|
||||
const char* test_case_name, CodeLocation code_location) {
|
||||
return GetTestSuitePatternHolder<TestCase>(test_case_name, code_location);
|
||||
}
|
||||
|
||||
#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
|
||||
|
||||
private:
|
||||
using TestSuiteInfoContainer = ::std::vector<ParameterizedTestSuiteInfoBase*>;
|
||||
|
||||
TestSuiteInfoContainer test_suite_infos_;
|
||||
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(ParameterizedTestSuiteRegistry);
|
||||
};
|
||||
|
||||
} // namespace internal
|
||||
|
||||
// Forward declarations of ValuesIn(), which is implemented in
|
||||
// include/gtest/gtest-param-test.h.
|
||||
template <class Container>
|
||||
internal::ParamGenerator<typename Container::value_type> ValuesIn(
|
||||
const Container& container);
|
||||
|
||||
namespace internal {
|
||||
// Used in the Values() function to provide polymorphic capabilities.
|
||||
|
||||
template <typename... Ts>
|
||||
class ValueArray {
|
||||
public:
|
||||
ValueArray(Ts... v) : v_{std::move(v)...} {}
|
||||
|
||||
template <typename T>
|
||||
operator ParamGenerator<T>() const { // NOLINT
|
||||
return ValuesIn(MakeVector<T>(MakeIndexSequence<sizeof...(Ts)>()));
|
||||
}
|
||||
|
||||
private:
|
||||
template <typename T, size_t... I>
|
||||
std::vector<T> MakeVector(IndexSequence<I...>) const {
|
||||
return std::vector<T>{static_cast<T>(v_.template Get<I>())...};
|
||||
}
|
||||
|
||||
FlatTuple<Ts...> v_;
|
||||
};
|
||||
|
||||
template <typename... T>
|
||||
class CartesianProductGenerator
|
||||
: public ParamGeneratorInterface<::std::tuple<T...>> {
|
||||
public:
|
||||
typedef ::std::tuple<T...> ParamType;
|
||||
|
||||
CartesianProductGenerator(const std::tuple<ParamGenerator<T>...>& g)
|
||||
: generators_(g) {}
|
||||
~CartesianProductGenerator() override {}
|
||||
|
||||
ParamIteratorInterface<ParamType>* Begin() const override {
|
||||
return new Iterator(this, generators_, false);
|
||||
}
|
||||
ParamIteratorInterface<ParamType>* End() const override {
|
||||
return new Iterator(this, generators_, true);
|
||||
}
|
||||
|
||||
private:
|
||||
template <class I>
|
||||
class IteratorImpl;
|
||||
template <size_t... I>
|
||||
class IteratorImpl<IndexSequence<I...>>
|
||||
: public ParamIteratorInterface<ParamType> {
|
||||
public:
|
||||
IteratorImpl(const ParamGeneratorInterface<ParamType>* base,
|
||||
const std::tuple<ParamGenerator<T>...>& generators, bool is_end)
|
||||
: base_(base),
|
||||
begin_(std::get<I>(generators).begin()...),
|
||||
end_(std::get<I>(generators).end()...),
|
||||
current_(is_end ? end_ : begin_) {
|
||||
ComputeCurrentValue();
|
||||
}
|
||||
~IteratorImpl() override {}
|
||||
|
||||
const ParamGeneratorInterface<ParamType>* BaseGenerator() const override {
|
||||
return base_;
|
||||
}
|
||||
// Advance should not be called on beyond-of-range iterators
|
||||
// so no component iterators must be beyond end of range, either.
|
||||
void Advance() override {
|
||||
assert(!AtEnd());
|
||||
// Advance the last iterator.
|
||||
++std::get<sizeof...(T) - 1>(current_);
|
||||
// if that reaches end, propagate that up.
|
||||
AdvanceIfEnd<sizeof...(T) - 1>();
|
||||
ComputeCurrentValue();
|
||||
}
|
||||
ParamIteratorInterface<ParamType>* Clone() const override {
|
||||
return new IteratorImpl(*this);
|
||||
}
|
||||
|
||||
const ParamType* Current() const override { return current_value_.get(); }
|
||||
|
||||
bool Equals(const ParamIteratorInterface<ParamType>& other) const override {
|
||||
// Having the same base generator guarantees that the other
|
||||
// iterator is of the same type and we can downcast.
|
||||
GTEST_CHECK_(BaseGenerator() == other.BaseGenerator())
|
||||
<< "The program attempted to compare iterators "
|
||||
<< "from different generators." << std::endl;
|
||||
const IteratorImpl* typed_other =
|
||||
CheckedDowncastToActualType<const IteratorImpl>(&other);
|
||||
|
||||
// We must report iterators equal if they both point beyond their
|
||||
// respective ranges. That can happen in a variety of fashions,
|
||||
// so we have to consult AtEnd().
|
||||
if (AtEnd() && typed_other->AtEnd()) return true;
|
||||
|
||||
bool same = true;
|
||||
bool dummy[] = {
|
||||
(same = same && std::get<I>(current_) ==
|
||||
std::get<I>(typed_other->current_))...};
|
||||
(void)dummy;
|
||||
return same;
|
||||
}
|
||||
|
||||
private:
|
||||
template <size_t ThisI>
|
||||
void AdvanceIfEnd() {
|
||||
if (std::get<ThisI>(current_) != std::get<ThisI>(end_)) return;
|
||||
|
||||
bool last = ThisI == 0;
|
||||
if (last) {
|
||||
// We are done. Nothing else to propagate.
|
||||
return;
|
||||
}
|
||||
|
||||
constexpr size_t NextI = ThisI - (ThisI != 0);
|
||||
std::get<ThisI>(current_) = std::get<ThisI>(begin_);
|
||||
++std::get<NextI>(current_);
|
||||
AdvanceIfEnd<NextI>();
|
||||
}
|
||||
|
||||
void ComputeCurrentValue() {
|
||||
if (!AtEnd())
|
||||
current_value_ = std::make_shared<ParamType>(*std::get<I>(current_)...);
|
||||
}
|
||||
bool AtEnd() const {
|
||||
bool at_end = false;
|
||||
bool dummy[] = {
|
||||
(at_end = at_end || std::get<I>(current_) == std::get<I>(end_))...};
|
||||
(void)dummy;
|
||||
return at_end;
|
||||
}
|
||||
|
||||
const ParamGeneratorInterface<ParamType>* const base_;
|
||||
std::tuple<typename ParamGenerator<T>::iterator...> begin_;
|
||||
std::tuple<typename ParamGenerator<T>::iterator...> end_;
|
||||
std::tuple<typename ParamGenerator<T>::iterator...> current_;
|
||||
std::shared_ptr<ParamType> current_value_;
|
||||
};
|
||||
|
||||
using Iterator = IteratorImpl<typename MakeIndexSequence<sizeof...(T)>::type>;
|
||||
|
||||
std::tuple<ParamGenerator<T>...> generators_;
|
||||
};
|
||||
|
||||
template <class... Gen>
|
||||
class CartesianProductHolder {
|
||||
public:
|
||||
CartesianProductHolder(const Gen&... g) : generators_(g...) {}
|
||||
template <typename... T>
|
||||
operator ParamGenerator<::std::tuple<T...>>() const {
|
||||
return ParamGenerator<::std::tuple<T...>>(
|
||||
new CartesianProductGenerator<T...>(generators_));
|
||||
}
|
||||
|
||||
private:
|
||||
std::tuple<Gen...> generators_;
|
||||
};
|
||||
|
||||
} // namespace internal
|
||||
} // namespace testing
|
||||
|
||||
#endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PARAM_UTIL_H_
|
||||
@@ -1,107 +0,0 @@
|
||||
// Copyright 2015, Google Inc.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// The Google C++ Testing and Mocking Framework (Google Test)
|
||||
//
|
||||
// This header file defines the GTEST_OS_* macro.
|
||||
// It is separate from gtest-port.h so that custom/gtest-port.h can include it.
|
||||
|
||||
#ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_ARCH_H_
|
||||
#define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_ARCH_H_
|
||||
|
||||
// Determines the platform on which Google Test is compiled.
|
||||
#ifdef __CYGWIN__
|
||||
# define GTEST_OS_CYGWIN 1
|
||||
# elif defined(__MINGW__) || defined(__MINGW32__) || defined(__MINGW64__)
|
||||
# define GTEST_OS_WINDOWS_MINGW 1
|
||||
# define GTEST_OS_WINDOWS 1
|
||||
#elif defined _WIN32
|
||||
# define GTEST_OS_WINDOWS 1
|
||||
# ifdef _WIN32_WCE
|
||||
# define GTEST_OS_WINDOWS_MOBILE 1
|
||||
# elif defined(WINAPI_FAMILY)
|
||||
# include <winapifamily.h>
|
||||
# if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
|
||||
# define GTEST_OS_WINDOWS_DESKTOP 1
|
||||
# elif WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_PHONE_APP)
|
||||
# define GTEST_OS_WINDOWS_PHONE 1
|
||||
# elif WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP)
|
||||
# define GTEST_OS_WINDOWS_RT 1
|
||||
# elif WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_TV_TITLE)
|
||||
# define GTEST_OS_WINDOWS_PHONE 1
|
||||
# define GTEST_OS_WINDOWS_TV_TITLE 1
|
||||
# else
|
||||
// WINAPI_FAMILY defined but no known partition matched.
|
||||
// Default to desktop.
|
||||
# define GTEST_OS_WINDOWS_DESKTOP 1
|
||||
# endif
|
||||
# else
|
||||
# define GTEST_OS_WINDOWS_DESKTOP 1
|
||||
# endif // _WIN32_WCE
|
||||
#elif defined __OS2__
|
||||
# define GTEST_OS_OS2 1
|
||||
#elif defined __APPLE__
|
||||
# define GTEST_OS_MAC 1
|
||||
# if TARGET_OS_IPHONE
|
||||
# define GTEST_OS_IOS 1
|
||||
# endif
|
||||
#elif defined __DragonFly__
|
||||
# define GTEST_OS_DRAGONFLY 1
|
||||
#elif defined __FreeBSD__
|
||||
# define GTEST_OS_FREEBSD 1
|
||||
#elif defined __Fuchsia__
|
||||
# define GTEST_OS_FUCHSIA 1
|
||||
#elif defined(__GLIBC__) && defined(__FreeBSD_kernel__)
|
||||
# define GTEST_OS_GNU_KFREEBSD 1
|
||||
#elif defined __linux__
|
||||
# define GTEST_OS_LINUX 1
|
||||
# if defined __ANDROID__
|
||||
# define GTEST_OS_LINUX_ANDROID 1
|
||||
# endif
|
||||
#elif defined __MVS__
|
||||
# define GTEST_OS_ZOS 1
|
||||
#elif defined(__sun) && defined(__SVR4)
|
||||
# define GTEST_OS_SOLARIS 1
|
||||
#elif defined(_AIX)
|
||||
# define GTEST_OS_AIX 1
|
||||
#elif defined(__hpux)
|
||||
# define GTEST_OS_HPUX 1
|
||||
#elif defined __native_client__
|
||||
# define GTEST_OS_NACL 1
|
||||
#elif defined __NetBSD__
|
||||
# define GTEST_OS_NETBSD 1
|
||||
#elif defined __OpenBSD__
|
||||
# define GTEST_OS_OPENBSD 1
|
||||
#elif defined __QNX__
|
||||
# define GTEST_OS_QNX 1
|
||||
#elif defined(__HAIKU__)
|
||||
#define GTEST_OS_HAIKU 1
|
||||
#endif // __CYGWIN__
|
||||
|
||||
#endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_ARCH_H_
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,171 +0,0 @@
|
||||
// Copyright 2005, Google Inc.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// The Google C++ Testing and Mocking Framework (Google Test)
|
||||
//
|
||||
// This header file declares the String class and functions used internally by
|
||||
// Google Test. They are subject to change without notice. They should not used
|
||||
// by code external to Google Test.
|
||||
//
|
||||
// This header file is #included by gtest-internal.h.
|
||||
// It should not be #included by other files.
|
||||
|
||||
// GOOGLETEST_CM0001 DO NOT DELETE
|
||||
|
||||
#ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_STRING_H_
|
||||
#define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_STRING_H_
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
// string.h is not guaranteed to provide strcpy on C++ Builder.
|
||||
# include <mem.h>
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
#include <string>
|
||||
|
||||
#include "gtest/internal/gtest-port.h"
|
||||
|
||||
namespace testing {
|
||||
namespace internal {
|
||||
|
||||
// String - an abstract class holding static string utilities.
|
||||
class GTEST_API_ String {
|
||||
public:
|
||||
// Static utility methods
|
||||
|
||||
// Clones a 0-terminated C string, allocating memory using new. The
|
||||
// caller is responsible for deleting the return value using
|
||||
// delete[]. Returns the cloned string, or NULL if the input is
|
||||
// NULL.
|
||||
//
|
||||
// This is different from strdup() in string.h, which allocates
|
||||
// memory using malloc().
|
||||
static const char* CloneCString(const char* c_str);
|
||||
|
||||
#if GTEST_OS_WINDOWS_MOBILE
|
||||
// Windows CE does not have the 'ANSI' versions of Win32 APIs. To be
|
||||
// able to pass strings to Win32 APIs on CE we need to convert them
|
||||
// to 'Unicode', UTF-16.
|
||||
|
||||
// Creates a UTF-16 wide string from the given ANSI string, allocating
|
||||
// memory using new. The caller is responsible for deleting the return
|
||||
// value using delete[]. Returns the wide string, or NULL if the
|
||||
// input is NULL.
|
||||
//
|
||||
// The wide string is created using the ANSI codepage (CP_ACP) to
|
||||
// match the behaviour of the ANSI versions of Win32 calls and the
|
||||
// C runtime.
|
||||
static LPCWSTR AnsiToUtf16(const char* c_str);
|
||||
|
||||
// Creates an ANSI string from the given wide string, allocating
|
||||
// memory using new. The caller is responsible for deleting the return
|
||||
// value using delete[]. Returns the ANSI string, or NULL if the
|
||||
// input is NULL.
|
||||
//
|
||||
// The returned string is created using the ANSI codepage (CP_ACP) to
|
||||
// match the behaviour of the ANSI versions of Win32 calls and the
|
||||
// C runtime.
|
||||
static const char* Utf16ToAnsi(LPCWSTR utf16_str);
|
||||
#endif
|
||||
|
||||
// Compares two C strings. Returns true if and only if they have the same
|
||||
// content.
|
||||
//
|
||||
// Unlike strcmp(), this function can handle NULL argument(s). A
|
||||
// NULL C string is considered different to any non-NULL C string,
|
||||
// including the empty string.
|
||||
static bool CStringEquals(const char* lhs, const char* rhs);
|
||||
|
||||
// Converts a wide C string to a String using the UTF-8 encoding.
|
||||
// NULL will be converted to "(null)". If an error occurred during
|
||||
// the conversion, "(failed to convert from wide string)" is
|
||||
// returned.
|
||||
static std::string ShowWideCString(const wchar_t* wide_c_str);
|
||||
|
||||
// Compares two wide C strings. Returns true if and only if they have the
|
||||
// same content.
|
||||
//
|
||||
// Unlike wcscmp(), this function can handle NULL argument(s). A
|
||||
// NULL C string is considered different to any non-NULL C string,
|
||||
// including the empty string.
|
||||
static bool WideCStringEquals(const wchar_t* lhs, const wchar_t* rhs);
|
||||
|
||||
// Compares two C strings, ignoring case. Returns true if and only if
|
||||
// they have the same content.
|
||||
//
|
||||
// Unlike strcasecmp(), this function can handle NULL argument(s).
|
||||
// A NULL C string is considered different to any non-NULL C string,
|
||||
// including the empty string.
|
||||
static bool CaseInsensitiveCStringEquals(const char* lhs,
|
||||
const char* rhs);
|
||||
|
||||
// Compares two wide C strings, ignoring case. Returns true if and only if
|
||||
// they have the same content.
|
||||
//
|
||||
// Unlike wcscasecmp(), this function can handle NULL argument(s).
|
||||
// A NULL C string is considered different to any non-NULL wide C string,
|
||||
// including the empty string.
|
||||
// NB: The implementations on different platforms slightly differ.
|
||||
// On windows, this method uses _wcsicmp which compares according to LC_CTYPE
|
||||
// environment variable. On GNU platform this method uses wcscasecmp
|
||||
// which compares according to LC_CTYPE category of the current locale.
|
||||
// On MacOS X, it uses towlower, which also uses LC_CTYPE category of the
|
||||
// current locale.
|
||||
static bool CaseInsensitiveWideCStringEquals(const wchar_t* lhs,
|
||||
const wchar_t* rhs);
|
||||
|
||||
// Returns true if and only if the given string ends with the given suffix,
|
||||
// ignoring case. Any string is considered to end with an empty suffix.
|
||||
static bool EndsWithCaseInsensitive(
|
||||
const std::string& str, const std::string& suffix);
|
||||
|
||||
// Formats an int value as "%02d".
|
||||
static std::string FormatIntWidth2(int value); // "%02d" for width == 2
|
||||
|
||||
// Formats an int value as "%X".
|
||||
static std::string FormatHexInt(int value);
|
||||
|
||||
// Formats an int value as "%X".
|
||||
static std::string FormatHexUInt32(UInt32 value);
|
||||
|
||||
// Formats a byte as "%02X".
|
||||
static std::string FormatByte(unsigned char value);
|
||||
|
||||
private:
|
||||
String(); // Not meant to be instantiated.
|
||||
}; // class String
|
||||
|
||||
// Gets the content of the stringstream's buffer as an std::string. Each '\0'
|
||||
// character in the buffer is replaced with "\\0".
|
||||
GTEST_API_ std::string StringStreamToString(::std::stringstream* stream);
|
||||
|
||||
} // namespace internal
|
||||
} // namespace testing
|
||||
|
||||
#endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_STRING_H_
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,302 +0,0 @@
|
||||
$$ -*- mode: c++; -*-
|
||||
$var n = 50 $$ Maximum length of type lists we want to support.
|
||||
// Copyright 2008 Google Inc.
|
||||
// All Rights Reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
|
||||
// Type utilities needed for implementing typed and type-parameterized
|
||||
// tests. This file is generated by a SCRIPT. DO NOT EDIT BY HAND!
|
||||
//
|
||||
// Currently we support at most $n types in a list, and at most $n
|
||||
// type-parameterized tests in one type-parameterized test suite.
|
||||
// Please contact googletestframework@googlegroups.com if you need
|
||||
// more.
|
||||
|
||||
// GOOGLETEST_CM0001 DO NOT DELETE
|
||||
|
||||
#ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TYPE_UTIL_H_
|
||||
#define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TYPE_UTIL_H_
|
||||
|
||||
#include "gtest/internal/gtest-port.h"
|
||||
|
||||
// #ifdef __GNUC__ is too general here. It is possible to use gcc without using
|
||||
// libstdc++ (which is where cxxabi.h comes from).
|
||||
# if GTEST_HAS_CXXABI_H_
|
||||
# include <cxxabi.h>
|
||||
# elif defined(__HP_aCC)
|
||||
# include <acxx_demangle.h>
|
||||
# endif // GTEST_HASH_CXXABI_H_
|
||||
|
||||
namespace testing {
|
||||
namespace internal {
|
||||
|
||||
// Canonicalizes a given name with respect to the Standard C++ Library.
|
||||
// This handles removing the inline namespace within `std` that is
|
||||
// used by various standard libraries (e.g., `std::__1`). Names outside
|
||||
// of namespace std are returned unmodified.
|
||||
inline std::string CanonicalizeForStdLibVersioning(std::string s) {
|
||||
static const char prefix[] = "std::__";
|
||||
if (s.compare(0, strlen(prefix), prefix) == 0) {
|
||||
std::string::size_type end = s.find("::", strlen(prefix));
|
||||
if (end != s.npos) {
|
||||
// Erase everything between the initial `std` and the second `::`.
|
||||
s.erase(strlen("std"), end - strlen("std"));
|
||||
}
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
// GetTypeName<T>() returns a human-readable name of type T.
|
||||
// NB: This function is also used in Google Mock, so don't move it inside of
|
||||
// the typed-test-only section below.
|
||||
template <typename T>
|
||||
std::string GetTypeName() {
|
||||
# if GTEST_HAS_RTTI
|
||||
|
||||
const char* const name = typeid(T).name();
|
||||
# if GTEST_HAS_CXXABI_H_ || defined(__HP_aCC)
|
||||
int status = 0;
|
||||
// gcc's implementation of typeid(T).name() mangles the type name,
|
||||
// so we have to demangle it.
|
||||
# if GTEST_HAS_CXXABI_H_
|
||||
using abi::__cxa_demangle;
|
||||
# endif // GTEST_HAS_CXXABI_H_
|
||||
char* const readable_name = __cxa_demangle(name, nullptr, nullptr, &status);
|
||||
const std::string name_str(status == 0 ? readable_name : name);
|
||||
free(readable_name);
|
||||
return CanonicalizeForStdLibVersioning(name_str);
|
||||
# else
|
||||
return name;
|
||||
# endif // GTEST_HAS_CXXABI_H_ || __HP_aCC
|
||||
|
||||
# else
|
||||
|
||||
return "<type>";
|
||||
|
||||
# endif // GTEST_HAS_RTTI
|
||||
}
|
||||
|
||||
#if GTEST_HAS_TYPED_TEST || GTEST_HAS_TYPED_TEST_P
|
||||
|
||||
// A unique type used as the default value for the arguments of class
|
||||
// template Types. This allows us to simulate variadic templates
|
||||
// (e.g. Types<int>, Type<int, double>, and etc), which C++ doesn't
|
||||
// support directly.
|
||||
struct None {};
|
||||
|
||||
// The following family of struct and struct templates are used to
|
||||
// represent type lists. In particular, TypesN<T1, T2, ..., TN>
|
||||
// represents a type list with N types (T1, T2, ..., and TN) in it.
|
||||
// Except for Types0, every struct in the family has two member types:
|
||||
// Head for the first type in the list, and Tail for the rest of the
|
||||
// list.
|
||||
|
||||
// The empty type list.
|
||||
struct Types0 {};
|
||||
|
||||
// Type lists of length 1, 2, 3, and so on.
|
||||
|
||||
template <typename T1>
|
||||
struct Types1 {
|
||||
typedef T1 Head;
|
||||
typedef Types0 Tail;
|
||||
};
|
||||
|
||||
$range i 2..n
|
||||
|
||||
$for i [[
|
||||
$range j 1..i
|
||||
$range k 2..i
|
||||
template <$for j, [[typename T$j]]>
|
||||
struct Types$i {
|
||||
typedef T1 Head;
|
||||
typedef Types$(i-1)<$for k, [[T$k]]> Tail;
|
||||
};
|
||||
|
||||
|
||||
]]
|
||||
|
||||
} // namespace internal
|
||||
|
||||
// We don't want to require the users to write TypesN<...> directly,
|
||||
// as that would require them to count the length. Types<...> is much
|
||||
// easier to write, but generates horrible messages when there is a
|
||||
// compiler error, as gcc insists on printing out each template
|
||||
// argument, even if it has the default value (this means Types<int>
|
||||
// will appear as Types<int, None, None, ..., None> in the compiler
|
||||
// errors).
|
||||
//
|
||||
// Our solution is to combine the best part of the two approaches: a
|
||||
// user would write Types<T1, ..., TN>, and Google Test will translate
|
||||
// that to TypesN<T1, ..., TN> internally to make error messages
|
||||
// readable. The translation is done by the 'type' member of the
|
||||
// Types template.
|
||||
|
||||
$range i 1..n
|
||||
template <$for i, [[typename T$i = internal::None]]>
|
||||
struct Types {
|
||||
typedef internal::Types$n<$for i, [[T$i]]> type;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct Types<$for i, [[internal::None]]> {
|
||||
typedef internal::Types0 type;
|
||||
};
|
||||
|
||||
$range i 1..n-1
|
||||
$for i [[
|
||||
$range j 1..i
|
||||
$range k i+1..n
|
||||
template <$for j, [[typename T$j]]>
|
||||
struct Types<$for j, [[T$j]]$for k[[, internal::None]]> {
|
||||
typedef internal::Types$i<$for j, [[T$j]]> type;
|
||||
};
|
||||
|
||||
]]
|
||||
|
||||
namespace internal {
|
||||
|
||||
# define GTEST_TEMPLATE_ template <typename T> class
|
||||
|
||||
// The template "selector" struct TemplateSel<Tmpl> is used to
|
||||
// represent Tmpl, which must be a class template with one type
|
||||
// parameter, as a type. TemplateSel<Tmpl>::Bind<T>::type is defined
|
||||
// as the type Tmpl<T>. This allows us to actually instantiate the
|
||||
// template "selected" by TemplateSel<Tmpl>.
|
||||
//
|
||||
// This trick is necessary for simulating typedef for class templates,
|
||||
// which C++ doesn't support directly.
|
||||
template <GTEST_TEMPLATE_ Tmpl>
|
||||
struct TemplateSel {
|
||||
template <typename T>
|
||||
struct Bind {
|
||||
typedef Tmpl<T> type;
|
||||
};
|
||||
};
|
||||
|
||||
# define GTEST_BIND_(TmplSel, T) \
|
||||
TmplSel::template Bind<T>::type
|
||||
|
||||
// A unique struct template used as the default value for the
|
||||
// arguments of class template Templates. This allows us to simulate
|
||||
// variadic templates (e.g. Templates<int>, Templates<int, double>,
|
||||
// and etc), which C++ doesn't support directly.
|
||||
template <typename T>
|
||||
struct NoneT {};
|
||||
|
||||
// The following family of struct and struct templates are used to
|
||||
// represent template lists. In particular, TemplatesN<T1, T2, ...,
|
||||
// TN> represents a list of N templates (T1, T2, ..., and TN). Except
|
||||
// for Templates0, every struct in the family has two member types:
|
||||
// Head for the selector of the first template in the list, and Tail
|
||||
// for the rest of the list.
|
||||
|
||||
// The empty template list.
|
||||
struct Templates0 {};
|
||||
|
||||
// Template lists of length 1, 2, 3, and so on.
|
||||
|
||||
template <GTEST_TEMPLATE_ T1>
|
||||
struct Templates1 {
|
||||
typedef TemplateSel<T1> Head;
|
||||
typedef Templates0 Tail;
|
||||
};
|
||||
|
||||
$range i 2..n
|
||||
|
||||
$for i [[
|
||||
$range j 1..i
|
||||
$range k 2..i
|
||||
template <$for j, [[GTEST_TEMPLATE_ T$j]]>
|
||||
struct Templates$i {
|
||||
typedef TemplateSel<T1> Head;
|
||||
typedef Templates$(i-1)<$for k, [[T$k]]> Tail;
|
||||
};
|
||||
|
||||
|
||||
]]
|
||||
|
||||
// We don't want to require the users to write TemplatesN<...> directly,
|
||||
// as that would require them to count the length. Templates<...> is much
|
||||
// easier to write, but generates horrible messages when there is a
|
||||
// compiler error, as gcc insists on printing out each template
|
||||
// argument, even if it has the default value (this means Templates<list>
|
||||
// will appear as Templates<list, NoneT, NoneT, ..., NoneT> in the compiler
|
||||
// errors).
|
||||
//
|
||||
// Our solution is to combine the best part of the two approaches: a
|
||||
// user would write Templates<T1, ..., TN>, and Google Test will translate
|
||||
// that to TemplatesN<T1, ..., TN> internally to make error messages
|
||||
// readable. The translation is done by the 'type' member of the
|
||||
// Templates template.
|
||||
|
||||
$range i 1..n
|
||||
template <$for i, [[GTEST_TEMPLATE_ T$i = NoneT]]>
|
||||
struct Templates {
|
||||
typedef Templates$n<$for i, [[T$i]]> type;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct Templates<$for i, [[NoneT]]> {
|
||||
typedef Templates0 type;
|
||||
};
|
||||
|
||||
$range i 1..n-1
|
||||
$for i [[
|
||||
$range j 1..i
|
||||
$range k i+1..n
|
||||
template <$for j, [[GTEST_TEMPLATE_ T$j]]>
|
||||
struct Templates<$for j, [[T$j]]$for k[[, NoneT]]> {
|
||||
typedef Templates$i<$for j, [[T$j]]> type;
|
||||
};
|
||||
|
||||
]]
|
||||
|
||||
// The TypeList template makes it possible to use either a single type
|
||||
// or a Types<...> list in TYPED_TEST_SUITE() and
|
||||
// INSTANTIATE_TYPED_TEST_SUITE_P().
|
||||
|
||||
template <typename T>
|
||||
struct TypeList {
|
||||
typedef Types1<T> type;
|
||||
};
|
||||
|
||||
|
||||
$range i 1..n
|
||||
template <$for i, [[typename T$i]]>
|
||||
struct TypeList<Types<$for i, [[T$i]]> > {
|
||||
typedef typename Types<$for i, [[T$i]]>::type type;
|
||||
};
|
||||
|
||||
#endif // GTEST_HAS_TYPED_TEST || GTEST_HAS_TYPED_TEST_P
|
||||
|
||||
} // namespace internal
|
||||
} // namespace testing
|
||||
|
||||
#endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TYPE_UTIL_H_
|
||||
@@ -1,130 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2010-2011, Pieter Noordhuis <pcnoordhuis at gmail dot com>
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of Redis nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without
|
||||
* specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef __HIREDIS_AE_H__
|
||||
#define __HIREDIS_AE_H__
|
||||
#include <sys/types.h>
|
||||
#include <ae.h>
|
||||
#include "../hiredis.h"
|
||||
#include "../async.h"
|
||||
|
||||
typedef struct redisAeEvents {
|
||||
redisAsyncContext *context;
|
||||
aeEventLoop *loop;
|
||||
int fd;
|
||||
int reading, writing;
|
||||
} redisAeEvents;
|
||||
|
||||
static void redisAeReadEvent(aeEventLoop *el, int fd, void *privdata, int mask) {
|
||||
((void)el); ((void)fd); ((void)mask);
|
||||
|
||||
redisAeEvents *e = (redisAeEvents*)privdata;
|
||||
redisAsyncHandleRead(e->context);
|
||||
}
|
||||
|
||||
static void redisAeWriteEvent(aeEventLoop *el, int fd, void *privdata, int mask) {
|
||||
((void)el); ((void)fd); ((void)mask);
|
||||
|
||||
redisAeEvents *e = (redisAeEvents*)privdata;
|
||||
redisAsyncHandleWrite(e->context);
|
||||
}
|
||||
|
||||
static void redisAeAddRead(void *privdata) {
|
||||
redisAeEvents *e = (redisAeEvents*)privdata;
|
||||
aeEventLoop *loop = e->loop;
|
||||
if (!e->reading) {
|
||||
e->reading = 1;
|
||||
aeCreateFileEvent(loop,e->fd,AE_READABLE,redisAeReadEvent,e);
|
||||
}
|
||||
}
|
||||
|
||||
static void redisAeDelRead(void *privdata) {
|
||||
redisAeEvents *e = (redisAeEvents*)privdata;
|
||||
aeEventLoop *loop = e->loop;
|
||||
if (e->reading) {
|
||||
e->reading = 0;
|
||||
aeDeleteFileEvent(loop,e->fd,AE_READABLE);
|
||||
}
|
||||
}
|
||||
|
||||
static void redisAeAddWrite(void *privdata) {
|
||||
redisAeEvents *e = (redisAeEvents*)privdata;
|
||||
aeEventLoop *loop = e->loop;
|
||||
if (!e->writing) {
|
||||
e->writing = 1;
|
||||
aeCreateFileEvent(loop,e->fd,AE_WRITABLE,redisAeWriteEvent,e);
|
||||
}
|
||||
}
|
||||
|
||||
static void redisAeDelWrite(void *privdata) {
|
||||
redisAeEvents *e = (redisAeEvents*)privdata;
|
||||
aeEventLoop *loop = e->loop;
|
||||
if (e->writing) {
|
||||
e->writing = 0;
|
||||
aeDeleteFileEvent(loop,e->fd,AE_WRITABLE);
|
||||
}
|
||||
}
|
||||
|
||||
static void redisAeCleanup(void *privdata) {
|
||||
redisAeEvents *e = (redisAeEvents*)privdata;
|
||||
redisAeDelRead(privdata);
|
||||
redisAeDelWrite(privdata);
|
||||
hi_free(e);
|
||||
}
|
||||
|
||||
static int redisAeAttach(aeEventLoop *loop, redisAsyncContext *ac) {
|
||||
redisContext *c = &(ac->c);
|
||||
redisAeEvents *e;
|
||||
|
||||
/* Nothing should be attached when something is already attached */
|
||||
if (ac->ev.data != NULL)
|
||||
return REDIS_ERR;
|
||||
|
||||
/* Create container for context and r/w events */
|
||||
e = (redisAeEvents*)hi_malloc(sizeof(*e));
|
||||
if (e == NULL)
|
||||
return REDIS_ERR;
|
||||
|
||||
e->context = ac;
|
||||
e->loop = loop;
|
||||
e->fd = c->fd;
|
||||
e->reading = e->writing = 0;
|
||||
|
||||
/* Register functions to start/stop listening for events */
|
||||
ac->ev.addRead = redisAeAddRead;
|
||||
ac->ev.delRead = redisAeDelRead;
|
||||
ac->ev.addWrite = redisAeAddWrite;
|
||||
ac->ev.delWrite = redisAeDelWrite;
|
||||
ac->ev.cleanup = redisAeCleanup;
|
||||
ac->ev.data = e;
|
||||
|
||||
return REDIS_OK;
|
||||
}
|
||||
#endif
|
||||
@@ -1,156 +0,0 @@
|
||||
#ifndef __HIREDIS_GLIB_H__
|
||||
#define __HIREDIS_GLIB_H__
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
#include "../hiredis.h"
|
||||
#include "../async.h"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
GSource source;
|
||||
redisAsyncContext *ac;
|
||||
GPollFD poll_fd;
|
||||
} RedisSource;
|
||||
|
||||
static void
|
||||
redis_source_add_read (gpointer data)
|
||||
{
|
||||
RedisSource *source = (RedisSource *)data;
|
||||
g_return_if_fail(source);
|
||||
source->poll_fd.events |= G_IO_IN;
|
||||
g_main_context_wakeup(g_source_get_context((GSource *)data));
|
||||
}
|
||||
|
||||
static void
|
||||
redis_source_del_read (gpointer data)
|
||||
{
|
||||
RedisSource *source = (RedisSource *)data;
|
||||
g_return_if_fail(source);
|
||||
source->poll_fd.events &= ~G_IO_IN;
|
||||
g_main_context_wakeup(g_source_get_context((GSource *)data));
|
||||
}
|
||||
|
||||
static void
|
||||
redis_source_add_write (gpointer data)
|
||||
{
|
||||
RedisSource *source = (RedisSource *)data;
|
||||
g_return_if_fail(source);
|
||||
source->poll_fd.events |= G_IO_OUT;
|
||||
g_main_context_wakeup(g_source_get_context((GSource *)data));
|
||||
}
|
||||
|
||||
static void
|
||||
redis_source_del_write (gpointer data)
|
||||
{
|
||||
RedisSource *source = (RedisSource *)data;
|
||||
g_return_if_fail(source);
|
||||
source->poll_fd.events &= ~G_IO_OUT;
|
||||
g_main_context_wakeup(g_source_get_context((GSource *)data));
|
||||
}
|
||||
|
||||
static void
|
||||
redis_source_cleanup (gpointer data)
|
||||
{
|
||||
RedisSource *source = (RedisSource *)data;
|
||||
|
||||
g_return_if_fail(source);
|
||||
|
||||
redis_source_del_read(source);
|
||||
redis_source_del_write(source);
|
||||
/*
|
||||
* It is not our responsibility to remove ourself from the
|
||||
* current main loop. However, we will remove the GPollFD.
|
||||
*/
|
||||
if (source->poll_fd.fd >= 0) {
|
||||
g_source_remove_poll((GSource *)data, &source->poll_fd);
|
||||
source->poll_fd.fd = -1;
|
||||
}
|
||||
}
|
||||
|
||||
static gboolean
|
||||
redis_source_prepare (GSource *source,
|
||||
gint *timeout_)
|
||||
{
|
||||
RedisSource *redis = (RedisSource *)source;
|
||||
*timeout_ = -1;
|
||||
return !!(redis->poll_fd.events & redis->poll_fd.revents);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
redis_source_check (GSource *source)
|
||||
{
|
||||
RedisSource *redis = (RedisSource *)source;
|
||||
return !!(redis->poll_fd.events & redis->poll_fd.revents);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
redis_source_dispatch (GSource *source,
|
||||
GSourceFunc callback,
|
||||
gpointer user_data)
|
||||
{
|
||||
RedisSource *redis = (RedisSource *)source;
|
||||
|
||||
if ((redis->poll_fd.revents & G_IO_OUT)) {
|
||||
redisAsyncHandleWrite(redis->ac);
|
||||
redis->poll_fd.revents &= ~G_IO_OUT;
|
||||
}
|
||||
|
||||
if ((redis->poll_fd.revents & G_IO_IN)) {
|
||||
redisAsyncHandleRead(redis->ac);
|
||||
redis->poll_fd.revents &= ~G_IO_IN;
|
||||
}
|
||||
|
||||
if (callback) {
|
||||
return callback(user_data);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
redis_source_finalize (GSource *source)
|
||||
{
|
||||
RedisSource *redis = (RedisSource *)source;
|
||||
|
||||
if (redis->poll_fd.fd >= 0) {
|
||||
g_source_remove_poll(source, &redis->poll_fd);
|
||||
redis->poll_fd.fd = -1;
|
||||
}
|
||||
}
|
||||
|
||||
static GSource *
|
||||
redis_source_new (redisAsyncContext *ac)
|
||||
{
|
||||
static GSourceFuncs source_funcs = {
|
||||
.prepare = redis_source_prepare,
|
||||
.check = redis_source_check,
|
||||
.dispatch = redis_source_dispatch,
|
||||
.finalize = redis_source_finalize,
|
||||
};
|
||||
redisContext *c = &ac->c;
|
||||
RedisSource *source;
|
||||
|
||||
g_return_val_if_fail(ac != NULL, NULL);
|
||||
|
||||
source = (RedisSource *)g_source_new(&source_funcs, sizeof *source);
|
||||
if (source == NULL)
|
||||
return NULL;
|
||||
|
||||
source->ac = ac;
|
||||
source->poll_fd.fd = c->fd;
|
||||
source->poll_fd.events = 0;
|
||||
source->poll_fd.revents = 0;
|
||||
g_source_add_poll((GSource *)source, &source->poll_fd);
|
||||
|
||||
ac->ev.addRead = redis_source_add_read;
|
||||
ac->ev.delRead = redis_source_del_read;
|
||||
ac->ev.addWrite = redis_source_add_write;
|
||||
ac->ev.delWrite = redis_source_del_write;
|
||||
ac->ev.cleanup = redis_source_cleanup;
|
||||
ac->ev.data = source;
|
||||
|
||||
return (GSource *)source;
|
||||
}
|
||||
|
||||
#endif /* __HIREDIS_GLIB_H__ */
|
||||
@@ -1,84 +0,0 @@
|
||||
#ifndef __HIREDIS_IVYKIS_H__
|
||||
#define __HIREDIS_IVYKIS_H__
|
||||
#include <iv.h>
|
||||
#include "../hiredis.h"
|
||||
#include "../async.h"
|
||||
|
||||
typedef struct redisIvykisEvents {
|
||||
redisAsyncContext *context;
|
||||
struct iv_fd fd;
|
||||
} redisIvykisEvents;
|
||||
|
||||
static void redisIvykisReadEvent(void *arg) {
|
||||
redisAsyncContext *context = (redisAsyncContext *)arg;
|
||||
redisAsyncHandleRead(context);
|
||||
}
|
||||
|
||||
static void redisIvykisWriteEvent(void *arg) {
|
||||
redisAsyncContext *context = (redisAsyncContext *)arg;
|
||||
redisAsyncHandleWrite(context);
|
||||
}
|
||||
|
||||
static void redisIvykisAddRead(void *privdata) {
|
||||
redisIvykisEvents *e = (redisIvykisEvents*)privdata;
|
||||
iv_fd_set_handler_in(&e->fd, redisIvykisReadEvent);
|
||||
}
|
||||
|
||||
static void redisIvykisDelRead(void *privdata) {
|
||||
redisIvykisEvents *e = (redisIvykisEvents*)privdata;
|
||||
iv_fd_set_handler_in(&e->fd, NULL);
|
||||
}
|
||||
|
||||
static void redisIvykisAddWrite(void *privdata) {
|
||||
redisIvykisEvents *e = (redisIvykisEvents*)privdata;
|
||||
iv_fd_set_handler_out(&e->fd, redisIvykisWriteEvent);
|
||||
}
|
||||
|
||||
static void redisIvykisDelWrite(void *privdata) {
|
||||
redisIvykisEvents *e = (redisIvykisEvents*)privdata;
|
||||
iv_fd_set_handler_out(&e->fd, NULL);
|
||||
}
|
||||
|
||||
static void redisIvykisCleanup(void *privdata) {
|
||||
redisIvykisEvents *e = (redisIvykisEvents*)privdata;
|
||||
|
||||
iv_fd_unregister(&e->fd);
|
||||
hi_free(e);
|
||||
}
|
||||
|
||||
static int redisIvykisAttach(redisAsyncContext *ac) {
|
||||
redisContext *c = &(ac->c);
|
||||
redisIvykisEvents *e;
|
||||
|
||||
/* Nothing should be attached when something is already attached */
|
||||
if (ac->ev.data != NULL)
|
||||
return REDIS_ERR;
|
||||
|
||||
/* Create container for context and r/w events */
|
||||
e = (redisIvykisEvents*)hi_malloc(sizeof(*e));
|
||||
if (e == NULL)
|
||||
return REDIS_ERR;
|
||||
|
||||
e->context = ac;
|
||||
|
||||
/* Register functions to start/stop listening for events */
|
||||
ac->ev.addRead = redisIvykisAddRead;
|
||||
ac->ev.delRead = redisIvykisDelRead;
|
||||
ac->ev.addWrite = redisIvykisAddWrite;
|
||||
ac->ev.delWrite = redisIvykisDelWrite;
|
||||
ac->ev.cleanup = redisIvykisCleanup;
|
||||
ac->ev.data = e;
|
||||
|
||||
/* Initialize and install read/write events */
|
||||
IV_FD_INIT(&e->fd);
|
||||
e->fd.fd = c->fd;
|
||||
e->fd.handler_in = redisIvykisReadEvent;
|
||||
e->fd.handler_out = redisIvykisWriteEvent;
|
||||
e->fd.handler_err = NULL;
|
||||
e->fd.cookie = e->context;
|
||||
|
||||
iv_fd_register(&e->fd);
|
||||
|
||||
return REDIS_OK;
|
||||
}
|
||||
#endif
|
||||
@@ -1,179 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2010-2011, Pieter Noordhuis <pcnoordhuis at gmail dot com>
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of Redis nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without
|
||||
* specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef __HIREDIS_LIBEV_H__
|
||||
#define __HIREDIS_LIBEV_H__
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
#include <ev.h>
|
||||
#include "../hiredis.h"
|
||||
#include "../async.h"
|
||||
|
||||
typedef struct redisLibevEvents {
|
||||
redisAsyncContext *context;
|
||||
struct ev_loop *loop;
|
||||
int reading, writing;
|
||||
ev_io rev, wev;
|
||||
ev_timer timer;
|
||||
} redisLibevEvents;
|
||||
|
||||
static void redisLibevReadEvent(EV_P_ ev_io *watcher, int revents) {
|
||||
#if EV_MULTIPLICITY
|
||||
((void)EV_A);
|
||||
#endif
|
||||
((void)revents);
|
||||
|
||||
redisLibevEvents *e = (redisLibevEvents*)watcher->data;
|
||||
redisAsyncHandleRead(e->context);
|
||||
}
|
||||
|
||||
static void redisLibevWriteEvent(EV_P_ ev_io *watcher, int revents) {
|
||||
#if EV_MULTIPLICITY
|
||||
((void)EV_A);
|
||||
#endif
|
||||
((void)revents);
|
||||
|
||||
redisLibevEvents *e = (redisLibevEvents*)watcher->data;
|
||||
redisAsyncHandleWrite(e->context);
|
||||
}
|
||||
|
||||
static void redisLibevAddRead(void *privdata) {
|
||||
redisLibevEvents *e = (redisLibevEvents*)privdata;
|
||||
struct ev_loop *loop = e->loop;
|
||||
((void)loop);
|
||||
if (!e->reading) {
|
||||
e->reading = 1;
|
||||
ev_io_start(EV_A_ &e->rev);
|
||||
}
|
||||
}
|
||||
|
||||
static void redisLibevDelRead(void *privdata) {
|
||||
redisLibevEvents *e = (redisLibevEvents*)privdata;
|
||||
struct ev_loop *loop = e->loop;
|
||||
((void)loop);
|
||||
if (e->reading) {
|
||||
e->reading = 0;
|
||||
ev_io_stop(EV_A_ &e->rev);
|
||||
}
|
||||
}
|
||||
|
||||
static void redisLibevAddWrite(void *privdata) {
|
||||
redisLibevEvents *e = (redisLibevEvents*)privdata;
|
||||
struct ev_loop *loop = e->loop;
|
||||
((void)loop);
|
||||
if (!e->writing) {
|
||||
e->writing = 1;
|
||||
ev_io_start(EV_A_ &e->wev);
|
||||
}
|
||||
}
|
||||
|
||||
static void redisLibevDelWrite(void *privdata) {
|
||||
redisLibevEvents *e = (redisLibevEvents*)privdata;
|
||||
struct ev_loop *loop = e->loop;
|
||||
((void)loop);
|
||||
if (e->writing) {
|
||||
e->writing = 0;
|
||||
ev_io_stop(EV_A_ &e->wev);
|
||||
}
|
||||
}
|
||||
|
||||
static void redisLibevStopTimer(void *privdata) {
|
||||
redisLibevEvents *e = (redisLibevEvents*)privdata;
|
||||
struct ev_loop *loop = e->loop;
|
||||
((void)loop);
|
||||
ev_timer_stop(EV_A_ &e->timer);
|
||||
}
|
||||
|
||||
static void redisLibevCleanup(void *privdata) {
|
||||
redisLibevEvents *e = (redisLibevEvents*)privdata;
|
||||
redisLibevDelRead(privdata);
|
||||
redisLibevDelWrite(privdata);
|
||||
redisLibevStopTimer(privdata);
|
||||
hi_free(e);
|
||||
}
|
||||
|
||||
static void redisLibevTimeout(EV_P_ ev_timer *timer, int revents) {
|
||||
((void)revents);
|
||||
redisLibevEvents *e = (redisLibevEvents*)timer->data;
|
||||
redisAsyncHandleTimeout(e->context);
|
||||
}
|
||||
|
||||
static void redisLibevSetTimeout(void *privdata, struct timeval tv) {
|
||||
redisLibevEvents *e = (redisLibevEvents*)privdata;
|
||||
struct ev_loop *loop = e->loop;
|
||||
((void)loop);
|
||||
|
||||
if (!ev_is_active(&e->timer)) {
|
||||
ev_init(&e->timer, redisLibevTimeout);
|
||||
e->timer.data = e;
|
||||
}
|
||||
|
||||
e->timer.repeat = tv.tv_sec + tv.tv_usec / 1000000.00;
|
||||
ev_timer_again(EV_A_ &e->timer);
|
||||
}
|
||||
|
||||
static int redisLibevAttach(EV_P_ redisAsyncContext *ac) {
|
||||
redisContext *c = &(ac->c);
|
||||
redisLibevEvents *e;
|
||||
|
||||
/* Nothing should be attached when something is already attached */
|
||||
if (ac->ev.data != NULL)
|
||||
return REDIS_ERR;
|
||||
|
||||
/* Create container for context and r/w events */
|
||||
e = (redisLibevEvents*)hi_calloc(1, sizeof(*e));
|
||||
if (e == NULL)
|
||||
return REDIS_ERR;
|
||||
|
||||
e->context = ac;
|
||||
#if EV_MULTIPLICITY
|
||||
e->loop = EV_A;
|
||||
#else
|
||||
e->loop = NULL;
|
||||
#endif
|
||||
e->rev.data = e;
|
||||
e->wev.data = e;
|
||||
|
||||
/* Register functions to start/stop listening for events */
|
||||
ac->ev.addRead = redisLibevAddRead;
|
||||
ac->ev.delRead = redisLibevDelRead;
|
||||
ac->ev.addWrite = redisLibevAddWrite;
|
||||
ac->ev.delWrite = redisLibevDelWrite;
|
||||
ac->ev.cleanup = redisLibevCleanup;
|
||||
ac->ev.scheduleTimer = redisLibevSetTimeout;
|
||||
ac->ev.data = e;
|
||||
|
||||
/* Initialize read/write events */
|
||||
ev_io_init(&e->rev,redisLibevReadEvent,c->fd,EV_READ);
|
||||
ev_io_init(&e->wev,redisLibevWriteEvent,c->fd,EV_WRITE);
|
||||
return REDIS_OK;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,175 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2010-2011, Pieter Noordhuis <pcnoordhuis at gmail dot com>
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of Redis nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without
|
||||
* specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef __HIREDIS_LIBEVENT_H__
|
||||
#define __HIREDIS_LIBEVENT_H__
|
||||
#include <event2/event.h>
|
||||
#include "../hiredis.h"
|
||||
#include "../async.h"
|
||||
|
||||
#define REDIS_LIBEVENT_DELETED 0x01
|
||||
#define REDIS_LIBEVENT_ENTERED 0x02
|
||||
|
||||
typedef struct redisLibeventEvents {
|
||||
redisAsyncContext *context;
|
||||
struct event *ev;
|
||||
struct event_base *base;
|
||||
struct timeval tv;
|
||||
short flags;
|
||||
short state;
|
||||
} redisLibeventEvents;
|
||||
|
||||
static void redisLibeventDestroy(redisLibeventEvents *e) {
|
||||
hi_free(e);
|
||||
}
|
||||
|
||||
static void redisLibeventHandler(int fd, short event, void *arg) {
|
||||
((void)fd);
|
||||
redisLibeventEvents *e = (redisLibeventEvents*)arg;
|
||||
e->state |= REDIS_LIBEVENT_ENTERED;
|
||||
|
||||
#define CHECK_DELETED() if (e->state & REDIS_LIBEVENT_DELETED) {\
|
||||
redisLibeventDestroy(e);\
|
||||
return; \
|
||||
}
|
||||
|
||||
if ((event & EV_TIMEOUT) && (e->state & REDIS_LIBEVENT_DELETED) == 0) {
|
||||
redisAsyncHandleTimeout(e->context);
|
||||
CHECK_DELETED();
|
||||
}
|
||||
|
||||
if ((event & EV_READ) && e->context && (e->state & REDIS_LIBEVENT_DELETED) == 0) {
|
||||
redisAsyncHandleRead(e->context);
|
||||
CHECK_DELETED();
|
||||
}
|
||||
|
||||
if ((event & EV_WRITE) && e->context && (e->state & REDIS_LIBEVENT_DELETED) == 0) {
|
||||
redisAsyncHandleWrite(e->context);
|
||||
CHECK_DELETED();
|
||||
}
|
||||
|
||||
e->state &= ~REDIS_LIBEVENT_ENTERED;
|
||||
#undef CHECK_DELETED
|
||||
}
|
||||
|
||||
static void redisLibeventUpdate(void *privdata, short flag, int isRemove) {
|
||||
redisLibeventEvents *e = (redisLibeventEvents *)privdata;
|
||||
const struct timeval *tv = e->tv.tv_sec || e->tv.tv_usec ? &e->tv : NULL;
|
||||
|
||||
if (isRemove) {
|
||||
if ((e->flags & flag) == 0) {
|
||||
return;
|
||||
} else {
|
||||
e->flags &= ~flag;
|
||||
}
|
||||
} else {
|
||||
if (e->flags & flag) {
|
||||
return;
|
||||
} else {
|
||||
e->flags |= flag;
|
||||
}
|
||||
}
|
||||
|
||||
event_del(e->ev);
|
||||
event_assign(e->ev, e->base, e->context->c.fd, e->flags | EV_PERSIST,
|
||||
redisLibeventHandler, privdata);
|
||||
event_add(e->ev, tv);
|
||||
}
|
||||
|
||||
static void redisLibeventAddRead(void *privdata) {
|
||||
redisLibeventUpdate(privdata, EV_READ, 0);
|
||||
}
|
||||
|
||||
static void redisLibeventDelRead(void *privdata) {
|
||||
redisLibeventUpdate(privdata, EV_READ, 1);
|
||||
}
|
||||
|
||||
static void redisLibeventAddWrite(void *privdata) {
|
||||
redisLibeventUpdate(privdata, EV_WRITE, 0);
|
||||
}
|
||||
|
||||
static void redisLibeventDelWrite(void *privdata) {
|
||||
redisLibeventUpdate(privdata, EV_WRITE, 1);
|
||||
}
|
||||
|
||||
static void redisLibeventCleanup(void *privdata) {
|
||||
redisLibeventEvents *e = (redisLibeventEvents*)privdata;
|
||||
if (!e) {
|
||||
return;
|
||||
}
|
||||
event_del(e->ev);
|
||||
event_free(e->ev);
|
||||
e->ev = NULL;
|
||||
|
||||
if (e->state & REDIS_LIBEVENT_ENTERED) {
|
||||
e->state |= REDIS_LIBEVENT_DELETED;
|
||||
} else {
|
||||
redisLibeventDestroy(e);
|
||||
}
|
||||
}
|
||||
|
||||
static void redisLibeventSetTimeout(void *privdata, struct timeval tv) {
|
||||
redisLibeventEvents *e = (redisLibeventEvents *)privdata;
|
||||
short flags = e->flags;
|
||||
e->flags = 0;
|
||||
e->tv = tv;
|
||||
redisLibeventUpdate(e, flags, 0);
|
||||
}
|
||||
|
||||
static int redisLibeventAttach(redisAsyncContext *ac, struct event_base *base) {
|
||||
redisContext *c = &(ac->c);
|
||||
redisLibeventEvents *e;
|
||||
|
||||
/* Nothing should be attached when something is already attached */
|
||||
if (ac->ev.data != NULL)
|
||||
return REDIS_ERR;
|
||||
|
||||
/* Create container for context and r/w events */
|
||||
e = (redisLibeventEvents*)hi_calloc(1, sizeof(*e));
|
||||
if (e == NULL)
|
||||
return REDIS_ERR;
|
||||
|
||||
e->context = ac;
|
||||
|
||||
/* Register functions to start/stop listening for events */
|
||||
ac->ev.addRead = redisLibeventAddRead;
|
||||
ac->ev.delRead = redisLibeventDelRead;
|
||||
ac->ev.addWrite = redisLibeventAddWrite;
|
||||
ac->ev.delWrite = redisLibeventDelWrite;
|
||||
ac->ev.cleanup = redisLibeventCleanup;
|
||||
ac->ev.scheduleTimer = redisLibeventSetTimeout;
|
||||
ac->ev.data = e;
|
||||
|
||||
/* Initialize and install read/write events */
|
||||
e->ev = event_new(base, c->fd, EV_READ | EV_WRITE, redisLibeventHandler, e);
|
||||
e->base = base;
|
||||
return REDIS_OK;
|
||||
}
|
||||
#endif
|
||||
@@ -1,117 +0,0 @@
|
||||
#ifndef __HIREDIS_LIBUV_H__
|
||||
#define __HIREDIS_LIBUV_H__
|
||||
#include <stdlib.h>
|
||||
#include <uv.h>
|
||||
#include "../hiredis.h"
|
||||
#include "../async.h"
|
||||
#include <string.h>
|
||||
|
||||
typedef struct redisLibuvEvents {
|
||||
redisAsyncContext* context;
|
||||
uv_poll_t handle;
|
||||
int events;
|
||||
} redisLibuvEvents;
|
||||
|
||||
|
||||
static void redisLibuvPoll(uv_poll_t* handle, int status, int events) {
|
||||
redisLibuvEvents* p = (redisLibuvEvents*)handle->data;
|
||||
int ev = (status ? p->events : events);
|
||||
|
||||
if (p->context != NULL && (ev & UV_READABLE)) {
|
||||
redisAsyncHandleRead(p->context);
|
||||
}
|
||||
if (p->context != NULL && (ev & UV_WRITABLE)) {
|
||||
redisAsyncHandleWrite(p->context);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void redisLibuvAddRead(void *privdata) {
|
||||
redisLibuvEvents* p = (redisLibuvEvents*)privdata;
|
||||
|
||||
p->events |= UV_READABLE;
|
||||
|
||||
uv_poll_start(&p->handle, p->events, redisLibuvPoll);
|
||||
}
|
||||
|
||||
|
||||
static void redisLibuvDelRead(void *privdata) {
|
||||
redisLibuvEvents* p = (redisLibuvEvents*)privdata;
|
||||
|
||||
p->events &= ~UV_READABLE;
|
||||
|
||||
if (p->events) {
|
||||
uv_poll_start(&p->handle, p->events, redisLibuvPoll);
|
||||
} else {
|
||||
uv_poll_stop(&p->handle);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void redisLibuvAddWrite(void *privdata) {
|
||||
redisLibuvEvents* p = (redisLibuvEvents*)privdata;
|
||||
|
||||
p->events |= UV_WRITABLE;
|
||||
|
||||
uv_poll_start(&p->handle, p->events, redisLibuvPoll);
|
||||
}
|
||||
|
||||
|
||||
static void redisLibuvDelWrite(void *privdata) {
|
||||
redisLibuvEvents* p = (redisLibuvEvents*)privdata;
|
||||
|
||||
p->events &= ~UV_WRITABLE;
|
||||
|
||||
if (p->events) {
|
||||
uv_poll_start(&p->handle, p->events, redisLibuvPoll);
|
||||
} else {
|
||||
uv_poll_stop(&p->handle);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void on_close(uv_handle_t* handle) {
|
||||
redisLibuvEvents* p = (redisLibuvEvents*)handle->data;
|
||||
|
||||
hi_free(p);
|
||||
}
|
||||
|
||||
|
||||
static void redisLibuvCleanup(void *privdata) {
|
||||
redisLibuvEvents* p = (redisLibuvEvents*)privdata;
|
||||
|
||||
p->context = NULL; // indicate that context might no longer exist
|
||||
uv_close((uv_handle_t*)&p->handle, on_close);
|
||||
}
|
||||
|
||||
|
||||
static int redisLibuvAttach(redisAsyncContext* ac, uv_loop_t* loop) {
|
||||
redisContext *c = &(ac->c);
|
||||
|
||||
if (ac->ev.data != NULL) {
|
||||
return REDIS_ERR;
|
||||
}
|
||||
|
||||
ac->ev.addRead = redisLibuvAddRead;
|
||||
ac->ev.delRead = redisLibuvDelRead;
|
||||
ac->ev.addWrite = redisLibuvAddWrite;
|
||||
ac->ev.delWrite = redisLibuvDelWrite;
|
||||
ac->ev.cleanup = redisLibuvCleanup;
|
||||
|
||||
redisLibuvEvents* p = (redisLibuvEvents*)hi_malloc(sizeof(*p));
|
||||
if (p == NULL)
|
||||
return REDIS_ERR;
|
||||
|
||||
memset(p, 0, sizeof(*p));
|
||||
|
||||
if (uv_poll_init_socket(loop, &p->handle, c->fd) != 0) {
|
||||
return REDIS_ERR;
|
||||
}
|
||||
|
||||
ac->ev.data = p;
|
||||
p->handle.data = p;
|
||||
p->context = ac;
|
||||
|
||||
return REDIS_OK;
|
||||
}
|
||||
#endif
|
||||
@@ -1,115 +0,0 @@
|
||||
//
|
||||
// Created by Дмитрий Бахвалов on 13.07.15.
|
||||
// Copyright (c) 2015 Dmitry Bakhvalov. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef __HIREDIS_MACOSX_H__
|
||||
#define __HIREDIS_MACOSX_H__
|
||||
|
||||
#include <CoreFoundation/CoreFoundation.h>
|
||||
|
||||
#include "../hiredis.h"
|
||||
#include "../async.h"
|
||||
|
||||
typedef struct {
|
||||
redisAsyncContext *context;
|
||||
CFSocketRef socketRef;
|
||||
CFRunLoopSourceRef sourceRef;
|
||||
} RedisRunLoop;
|
||||
|
||||
static int freeRedisRunLoop(RedisRunLoop* redisRunLoop) {
|
||||
if( redisRunLoop != NULL ) {
|
||||
if( redisRunLoop->sourceRef != NULL ) {
|
||||
CFRunLoopSourceInvalidate(redisRunLoop->sourceRef);
|
||||
CFRelease(redisRunLoop->sourceRef);
|
||||
}
|
||||
if( redisRunLoop->socketRef != NULL ) {
|
||||
CFSocketInvalidate(redisRunLoop->socketRef);
|
||||
CFRelease(redisRunLoop->socketRef);
|
||||
}
|
||||
hi_free(redisRunLoop);
|
||||
}
|
||||
return REDIS_ERR;
|
||||
}
|
||||
|
||||
static void redisMacOSAddRead(void *privdata) {
|
||||
RedisRunLoop *redisRunLoop = (RedisRunLoop*)privdata;
|
||||
CFSocketEnableCallBacks(redisRunLoop->socketRef, kCFSocketReadCallBack);
|
||||
}
|
||||
|
||||
static void redisMacOSDelRead(void *privdata) {
|
||||
RedisRunLoop *redisRunLoop = (RedisRunLoop*)privdata;
|
||||
CFSocketDisableCallBacks(redisRunLoop->socketRef, kCFSocketReadCallBack);
|
||||
}
|
||||
|
||||
static void redisMacOSAddWrite(void *privdata) {
|
||||
RedisRunLoop *redisRunLoop = (RedisRunLoop*)privdata;
|
||||
CFSocketEnableCallBacks(redisRunLoop->socketRef, kCFSocketWriteCallBack);
|
||||
}
|
||||
|
||||
static void redisMacOSDelWrite(void *privdata) {
|
||||
RedisRunLoop *redisRunLoop = (RedisRunLoop*)privdata;
|
||||
CFSocketDisableCallBacks(redisRunLoop->socketRef, kCFSocketWriteCallBack);
|
||||
}
|
||||
|
||||
static void redisMacOSCleanup(void *privdata) {
|
||||
RedisRunLoop *redisRunLoop = (RedisRunLoop*)privdata;
|
||||
freeRedisRunLoop(redisRunLoop);
|
||||
}
|
||||
|
||||
static void redisMacOSAsyncCallback(CFSocketRef __unused s, CFSocketCallBackType callbackType, CFDataRef __unused address, const void __unused *data, void *info) {
|
||||
redisAsyncContext* context = (redisAsyncContext*) info;
|
||||
|
||||
switch (callbackType) {
|
||||
case kCFSocketReadCallBack:
|
||||
redisAsyncHandleRead(context);
|
||||
break;
|
||||
|
||||
case kCFSocketWriteCallBack:
|
||||
redisAsyncHandleWrite(context);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static int redisMacOSAttach(redisAsyncContext *redisAsyncCtx, CFRunLoopRef runLoop) {
|
||||
redisContext *redisCtx = &(redisAsyncCtx->c);
|
||||
|
||||
/* Nothing should be attached when something is already attached */
|
||||
if( redisAsyncCtx->ev.data != NULL ) return REDIS_ERR;
|
||||
|
||||
RedisRunLoop* redisRunLoop = (RedisRunLoop*) hi_calloc(1, sizeof(RedisRunLoop));
|
||||
if (redisRunLoop == NULL)
|
||||
return REDIS_ERR;
|
||||
|
||||
/* Setup redis stuff */
|
||||
redisRunLoop->context = redisAsyncCtx;
|
||||
|
||||
redisAsyncCtx->ev.addRead = redisMacOSAddRead;
|
||||
redisAsyncCtx->ev.delRead = redisMacOSDelRead;
|
||||
redisAsyncCtx->ev.addWrite = redisMacOSAddWrite;
|
||||
redisAsyncCtx->ev.delWrite = redisMacOSDelWrite;
|
||||
redisAsyncCtx->ev.cleanup = redisMacOSCleanup;
|
||||
redisAsyncCtx->ev.data = redisRunLoop;
|
||||
|
||||
/* Initialize and install read/write events */
|
||||
CFSocketContext socketCtx = { 0, redisAsyncCtx, NULL, NULL, NULL };
|
||||
|
||||
redisRunLoop->socketRef = CFSocketCreateWithNative(NULL, redisCtx->fd,
|
||||
kCFSocketReadCallBack | kCFSocketWriteCallBack,
|
||||
redisMacOSAsyncCallback,
|
||||
&socketCtx);
|
||||
if( !redisRunLoop->socketRef ) return freeRedisRunLoop(redisRunLoop);
|
||||
|
||||
redisRunLoop->sourceRef = CFSocketCreateRunLoopSource(NULL, redisRunLoop->socketRef, 0);
|
||||
if( !redisRunLoop->sourceRef ) return freeRedisRunLoop(redisRunLoop);
|
||||
|
||||
CFRunLoopAddSource(runLoop, redisRunLoop->sourceRef, kCFRunLoopDefaultMode);
|
||||
|
||||
return REDIS_OK;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,135 +0,0 @@
|
||||
/*-
|
||||
* Copyright (C) 2014 Pietro Cerutti <gahr@gahr.ch>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef __HIREDIS_QT_H__
|
||||
#define __HIREDIS_QT_H__
|
||||
#include <QSocketNotifier>
|
||||
#include "../async.h"
|
||||
|
||||
static void RedisQtAddRead(void *);
|
||||
static void RedisQtDelRead(void *);
|
||||
static void RedisQtAddWrite(void *);
|
||||
static void RedisQtDelWrite(void *);
|
||||
static void RedisQtCleanup(void *);
|
||||
|
||||
class RedisQtAdapter : public QObject {
|
||||
|
||||
Q_OBJECT
|
||||
|
||||
friend
|
||||
void RedisQtAddRead(void * adapter) {
|
||||
RedisQtAdapter * a = static_cast<RedisQtAdapter *>(adapter);
|
||||
a->addRead();
|
||||
}
|
||||
|
||||
friend
|
||||
void RedisQtDelRead(void * adapter) {
|
||||
RedisQtAdapter * a = static_cast<RedisQtAdapter *>(adapter);
|
||||
a->delRead();
|
||||
}
|
||||
|
||||
friend
|
||||
void RedisQtAddWrite(void * adapter) {
|
||||
RedisQtAdapter * a = static_cast<RedisQtAdapter *>(adapter);
|
||||
a->addWrite();
|
||||
}
|
||||
|
||||
friend
|
||||
void RedisQtDelWrite(void * adapter) {
|
||||
RedisQtAdapter * a = static_cast<RedisQtAdapter *>(adapter);
|
||||
a->delWrite();
|
||||
}
|
||||
|
||||
friend
|
||||
void RedisQtCleanup(void * adapter) {
|
||||
RedisQtAdapter * a = static_cast<RedisQtAdapter *>(adapter);
|
||||
a->cleanup();
|
||||
}
|
||||
|
||||
public:
|
||||
RedisQtAdapter(QObject * parent = 0)
|
||||
: QObject(parent), m_ctx(0), m_read(0), m_write(0) { }
|
||||
|
||||
~RedisQtAdapter() {
|
||||
if (m_ctx != 0) {
|
||||
m_ctx->ev.data = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
int setContext(redisAsyncContext * ac) {
|
||||
if (ac->ev.data != NULL) {
|
||||
return REDIS_ERR;
|
||||
}
|
||||
m_ctx = ac;
|
||||
m_ctx->ev.data = this;
|
||||
m_ctx->ev.addRead = RedisQtAddRead;
|
||||
m_ctx->ev.delRead = RedisQtDelRead;
|
||||
m_ctx->ev.addWrite = RedisQtAddWrite;
|
||||
m_ctx->ev.delWrite = RedisQtDelWrite;
|
||||
m_ctx->ev.cleanup = RedisQtCleanup;
|
||||
return REDIS_OK;
|
||||
}
|
||||
|
||||
private:
|
||||
void addRead() {
|
||||
if (m_read) return;
|
||||
m_read = new QSocketNotifier(m_ctx->c.fd, QSocketNotifier::Read, 0);
|
||||
connect(m_read, SIGNAL(activated(int)), this, SLOT(read()));
|
||||
}
|
||||
|
||||
void delRead() {
|
||||
if (!m_read) return;
|
||||
delete m_read;
|
||||
m_read = 0;
|
||||
}
|
||||
|
||||
void addWrite() {
|
||||
if (m_write) return;
|
||||
m_write = new QSocketNotifier(m_ctx->c.fd, QSocketNotifier::Write, 0);
|
||||
connect(m_write, SIGNAL(activated(int)), this, SLOT(write()));
|
||||
}
|
||||
|
||||
void delWrite() {
|
||||
if (!m_write) return;
|
||||
delete m_write;
|
||||
m_write = 0;
|
||||
}
|
||||
|
||||
void cleanup() {
|
||||
delRead();
|
||||
delWrite();
|
||||
}
|
||||
|
||||
private slots:
|
||||
void read() { redisAsyncHandleRead(m_ctx); }
|
||||
void write() { redisAsyncHandleWrite(m_ctx); }
|
||||
|
||||
private:
|
||||
redisAsyncContext * m_ctx;
|
||||
QSocketNotifier * m_read;
|
||||
QSocketNotifier * m_write;
|
||||
};
|
||||
|
||||
#endif /* !__HIREDIS_QT_H__ */
|
||||
@@ -1,91 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2020, Michael Grunder <michael dot grunder at gmail dot com>
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of Redis nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without
|
||||
* specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef HIREDIS_ALLOC_H
|
||||
#define HIREDIS_ALLOC_H
|
||||
|
||||
#include <stddef.h> /* for size_t */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Structure pointing to our actually configured allocators */
|
||||
typedef struct hiredisAllocFuncs {
|
||||
void *(*mallocFn)(size_t);
|
||||
void *(*callocFn)(size_t,size_t);
|
||||
void *(*reallocFn)(void*,size_t);
|
||||
char *(*strdupFn)(const char*);
|
||||
void (*freeFn)(void*);
|
||||
} hiredisAllocFuncs;
|
||||
|
||||
hiredisAllocFuncs hiredisSetAllocators(hiredisAllocFuncs *ha);
|
||||
void hiredisResetAllocators(void);
|
||||
|
||||
#ifndef _WIN32
|
||||
|
||||
/* Hiredis' configured allocator function pointer struct */
|
||||
extern hiredisAllocFuncs hiredisAllocFns;
|
||||
|
||||
static inline void *hi_malloc(size_t size) {
|
||||
return hiredisAllocFns.mallocFn(size);
|
||||
}
|
||||
|
||||
static inline void *hi_calloc(size_t nmemb, size_t size) {
|
||||
return hiredisAllocFns.callocFn(nmemb, size);
|
||||
}
|
||||
|
||||
static inline void *hi_realloc(void *ptr, size_t size) {
|
||||
return hiredisAllocFns.reallocFn(ptr, size);
|
||||
}
|
||||
|
||||
static inline char *hi_strdup(const char *str) {
|
||||
return hiredisAllocFns.strdupFn(str);
|
||||
}
|
||||
|
||||
static inline void hi_free(void *ptr) {
|
||||
hiredisAllocFns.freeFn(ptr);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
void *hi_malloc(size_t size);
|
||||
void *hi_calloc(size_t nmemb, size_t size);
|
||||
void *hi_realloc(void *ptr, size_t size);
|
||||
char *hi_strdup(const char *str);
|
||||
void hi_free(void *ptr);
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* HIREDIS_ALLOC_H */
|
||||
@@ -1,147 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2009-2011, Salvatore Sanfilippo <antirez at gmail dot com>
|
||||
* Copyright (c) 2010-2011, Pieter Noordhuis <pcnoordhuis at gmail dot com>
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of Redis nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without
|
||||
* specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef __HIREDIS_ASYNC_H
|
||||
#define __HIREDIS_ASYNC_H
|
||||
#include "hiredis.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct redisAsyncContext; /* need forward declaration of redisAsyncContext */
|
||||
struct dict; /* dictionary header is included in async.c */
|
||||
|
||||
/* Reply callback prototype and container */
|
||||
typedef void (redisCallbackFn)(struct redisAsyncContext*, void*, void*);
|
||||
typedef struct redisCallback {
|
||||
struct redisCallback *next; /* simple singly linked list */
|
||||
redisCallbackFn *fn;
|
||||
int pending_subs;
|
||||
void *privdata;
|
||||
} redisCallback;
|
||||
|
||||
/* List of callbacks for either regular replies or pub/sub */
|
||||
typedef struct redisCallbackList {
|
||||
redisCallback *head, *tail;
|
||||
} redisCallbackList;
|
||||
|
||||
/* Connection callback prototypes */
|
||||
typedef void (redisDisconnectCallback)(const struct redisAsyncContext*, int status);
|
||||
typedef void (redisConnectCallback)(const struct redisAsyncContext*, int status);
|
||||
typedef void(redisTimerCallback)(void *timer, void *privdata);
|
||||
|
||||
/* Context for an async connection to Redis */
|
||||
typedef struct redisAsyncContext {
|
||||
/* Hold the regular context, so it can be realloc'ed. */
|
||||
redisContext c;
|
||||
|
||||
/* Setup error flags so they can be used directly. */
|
||||
int err;
|
||||
char *errstr;
|
||||
|
||||
/* Not used by hiredis */
|
||||
void *data;
|
||||
void (*dataCleanup)(void *privdata);
|
||||
|
||||
/* Event library data and hooks */
|
||||
struct {
|
||||
void *data;
|
||||
|
||||
/* Hooks that are called when the library expects to start
|
||||
* reading/writing. These functions should be idempotent. */
|
||||
void (*addRead)(void *privdata);
|
||||
void (*delRead)(void *privdata);
|
||||
void (*addWrite)(void *privdata);
|
||||
void (*delWrite)(void *privdata);
|
||||
void (*cleanup)(void *privdata);
|
||||
void (*scheduleTimer)(void *privdata, struct timeval tv);
|
||||
} ev;
|
||||
|
||||
/* Called when either the connection is terminated due to an error or per
|
||||
* user request. The status is set accordingly (REDIS_OK, REDIS_ERR). */
|
||||
redisDisconnectCallback *onDisconnect;
|
||||
|
||||
/* Called when the first write event was received. */
|
||||
redisConnectCallback *onConnect;
|
||||
|
||||
/* Regular command callbacks */
|
||||
redisCallbackList replies;
|
||||
|
||||
/* Address used for connect() */
|
||||
struct sockaddr *saddr;
|
||||
size_t addrlen;
|
||||
|
||||
/* Subscription callbacks */
|
||||
struct {
|
||||
redisCallbackList invalid;
|
||||
struct dict *channels;
|
||||
struct dict *patterns;
|
||||
} sub;
|
||||
|
||||
/* Any configured RESP3 PUSH handler */
|
||||
redisAsyncPushFn *push_cb;
|
||||
} redisAsyncContext;
|
||||
|
||||
/* Functions that proxy to hiredis */
|
||||
redisAsyncContext *redisAsyncConnectWithOptions(const redisOptions *options);
|
||||
redisAsyncContext *redisAsyncConnect(const char *ip, int port);
|
||||
redisAsyncContext *redisAsyncConnectBind(const char *ip, int port, const char *source_addr);
|
||||
redisAsyncContext *redisAsyncConnectBindWithReuse(const char *ip, int port,
|
||||
const char *source_addr);
|
||||
redisAsyncContext *redisAsyncConnectUnix(const char *path);
|
||||
int redisAsyncSetConnectCallback(redisAsyncContext *ac, redisConnectCallback *fn);
|
||||
int redisAsyncSetDisconnectCallback(redisAsyncContext *ac, redisDisconnectCallback *fn);
|
||||
|
||||
redisAsyncPushFn *redisAsyncSetPushCallback(redisAsyncContext *ac, redisAsyncPushFn *fn);
|
||||
int redisAsyncSetTimeout(redisAsyncContext *ac, struct timeval tv);
|
||||
void redisAsyncDisconnect(redisAsyncContext *ac);
|
||||
void redisAsyncFree(redisAsyncContext *ac);
|
||||
|
||||
/* Handle read/write events */
|
||||
void redisAsyncHandleRead(redisAsyncContext *ac);
|
||||
void redisAsyncHandleWrite(redisAsyncContext *ac);
|
||||
void redisAsyncHandleTimeout(redisAsyncContext *ac);
|
||||
void redisAsyncRead(redisAsyncContext *ac);
|
||||
void redisAsyncWrite(redisAsyncContext *ac);
|
||||
|
||||
/* Command functions for an async context. Write the command to the
|
||||
* output buffer and register the provided callback. */
|
||||
int redisvAsyncCommand(redisAsyncContext *ac, redisCallbackFn *fn, void *privdata, const char *format, va_list ap);
|
||||
int redisAsyncCommand(redisAsyncContext *ac, redisCallbackFn *fn, void *privdata, const char *format, ...);
|
||||
int redisAsyncCommandArgv(redisAsyncContext *ac, redisCallbackFn *fn, void *privdata, int argc, const char **argv, const size_t *argvlen);
|
||||
int redisAsyncFormattedCommand(redisAsyncContext *ac, redisCallbackFn *fn, void *privdata, const char *cmd, size_t len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,337 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2009-2011, Salvatore Sanfilippo <antirez at gmail dot com>
|
||||
* Copyright (c) 2010-2014, Pieter Noordhuis <pcnoordhuis at gmail dot com>
|
||||
* Copyright (c) 2015, Matt Stancliff <matt at genges dot com>,
|
||||
* Jan-Erik Rediger <janerik at fnordig dot com>
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of Redis nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without
|
||||
* specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef __HIREDIS_H
|
||||
#define __HIREDIS_H
|
||||
#include "read.h"
|
||||
#include <stdarg.h> /* for va_list */
|
||||
#ifndef _MSC_VER
|
||||
#include <sys/time.h> /* for struct timeval */
|
||||
#else
|
||||
struct timeval; /* forward declaration */
|
||||
typedef long long ssize_t;
|
||||
#endif
|
||||
#include <stdint.h> /* uintXX_t, etc */
|
||||
#include "sds.h" /* for sds */
|
||||
#include "alloc.h" /* for allocation wrappers */
|
||||
|
||||
#define HIREDIS_MAJOR 1
|
||||
#define HIREDIS_MINOR 0
|
||||
#define HIREDIS_PATCH 1
|
||||
#define HIREDIS_SONAME 1.0.1-dev
|
||||
|
||||
/* Connection type can be blocking or non-blocking and is set in the
|
||||
* least significant bit of the flags field in redisContext. */
|
||||
#define REDIS_BLOCK 0x1
|
||||
|
||||
/* Connection may be disconnected before being free'd. The second bit
|
||||
* in the flags field is set when the context is connected. */
|
||||
#define REDIS_CONNECTED 0x2
|
||||
|
||||
/* The async API might try to disconnect cleanly and flush the output
|
||||
* buffer and read all subsequent replies before disconnecting.
|
||||
* This flag means no new commands can come in and the connection
|
||||
* should be terminated once all replies have been read. */
|
||||
#define REDIS_DISCONNECTING 0x4
|
||||
|
||||
/* Flag specific to the async API which means that the context should be clean
|
||||
* up as soon as possible. */
|
||||
#define REDIS_FREEING 0x8
|
||||
|
||||
/* Flag that is set when an async callback is executed. */
|
||||
#define REDIS_IN_CALLBACK 0x10
|
||||
|
||||
/* Flag that is set when the async context has one or more subscriptions. */
|
||||
#define REDIS_SUBSCRIBED 0x20
|
||||
|
||||
/* Flag that is set when monitor mode is active */
|
||||
#define REDIS_MONITORING 0x40
|
||||
|
||||
/* Flag that is set when we should set SO_REUSEADDR before calling bind() */
|
||||
#define REDIS_REUSEADDR 0x80
|
||||
|
||||
/**
|
||||
* Flag that indicates the user does not want the context to
|
||||
* be automatically freed upon error
|
||||
*/
|
||||
#define REDIS_NO_AUTO_FREE 0x200
|
||||
|
||||
#define REDIS_KEEPALIVE_INTERVAL 15 /* seconds */
|
||||
|
||||
/* number of times we retry to connect in the case of EADDRNOTAVAIL and
|
||||
* SO_REUSEADDR is being used. */
|
||||
#define REDIS_CONNECT_RETRIES 10
|
||||
|
||||
/* Forward declarations for structs defined elsewhere */
|
||||
struct redisAsyncContext;
|
||||
struct redisContext;
|
||||
|
||||
/* RESP3 push helpers and callback prototypes */
|
||||
#define redisIsPushReply(r) (((redisReply*)(r))->type == REDIS_REPLY_PUSH)
|
||||
typedef void (redisPushFn)(void *, void *);
|
||||
typedef void (redisAsyncPushFn)(struct redisAsyncContext *, void *);
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* This is the reply object returned by redisCommand() */
|
||||
typedef struct redisReply {
|
||||
int type; /* REDIS_REPLY_* */
|
||||
long long integer; /* The integer when type is REDIS_REPLY_INTEGER */
|
||||
double dval; /* The double when type is REDIS_REPLY_DOUBLE */
|
||||
size_t len; /* Length of string */
|
||||
char *str; /* Used for REDIS_REPLY_ERROR, REDIS_REPLY_STRING
|
||||
REDIS_REPLY_VERB, REDIS_REPLY_DOUBLE (in additional to dval),
|
||||
and REDIS_REPLY_BIGNUM. */
|
||||
char vtype[4]; /* Used for REDIS_REPLY_VERB, contains the null
|
||||
terminated 3 character content type, such as "txt". */
|
||||
size_t elements; /* number of elements, for REDIS_REPLY_ARRAY */
|
||||
struct redisReply **element; /* elements vector for REDIS_REPLY_ARRAY */
|
||||
} redisReply;
|
||||
|
||||
redisReader *redisReaderCreate(void);
|
||||
|
||||
/* Function to free the reply objects hiredis returns by default. */
|
||||
void freeReplyObject(void *reply);
|
||||
|
||||
/* Functions to format a command according to the protocol. */
|
||||
int redisvFormatCommand(char **target, const char *format, va_list ap);
|
||||
int redisFormatCommand(char **target, const char *format, ...);
|
||||
int redisFormatCommandArgv(char **target, int argc, const char **argv, const size_t *argvlen);
|
||||
int redisFormatSdsCommandArgv(sds *target, int argc, const char ** argv, const size_t *argvlen);
|
||||
void redisFreeCommand(char *cmd);
|
||||
void redisFreeSdsCommand(sds cmd);
|
||||
|
||||
enum redisConnectionType {
|
||||
REDIS_CONN_TCP,
|
||||
REDIS_CONN_UNIX,
|
||||
REDIS_CONN_USERFD
|
||||
};
|
||||
|
||||
struct redisSsl;
|
||||
|
||||
#define REDIS_OPT_NONBLOCK 0x01
|
||||
#define REDIS_OPT_REUSEADDR 0x02
|
||||
|
||||
/**
|
||||
* Don't automatically free the async object on a connection failure,
|
||||
* or other implicit conditions. Only free on an explicit call to disconnect() or free()
|
||||
*/
|
||||
#define REDIS_OPT_NOAUTOFREE 0x04
|
||||
|
||||
/* Don't automatically intercept and free RESP3 PUSH replies. */
|
||||
#define REDIS_OPT_NO_PUSH_AUTOFREE 0x08
|
||||
|
||||
/* In Unix systems a file descriptor is a regular signed int, with -1
|
||||
* representing an invalid descriptor. In Windows it is a SOCKET
|
||||
* (32- or 64-bit unsigned integer depending on the architecture), where
|
||||
* all bits set (~0) is INVALID_SOCKET. */
|
||||
#ifndef _WIN32
|
||||
typedef int redisFD;
|
||||
#define REDIS_INVALID_FD -1
|
||||
#else
|
||||
#ifdef _WIN64
|
||||
typedef unsigned long long redisFD; /* SOCKET = 64-bit UINT_PTR */
|
||||
#else
|
||||
typedef unsigned long redisFD; /* SOCKET = 32-bit UINT_PTR */
|
||||
#endif
|
||||
#define REDIS_INVALID_FD ((redisFD)(~0)) /* INVALID_SOCKET */
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
/*
|
||||
* the type of connection to use. This also indicates which
|
||||
* `endpoint` member field to use
|
||||
*/
|
||||
int type;
|
||||
/* bit field of REDIS_OPT_xxx */
|
||||
int options;
|
||||
/* timeout value for connect operation. If NULL, no timeout is used */
|
||||
const struct timeval *connect_timeout;
|
||||
/* timeout value for commands. If NULL, no timeout is used. This can be
|
||||
* updated at runtime with redisSetTimeout/redisAsyncSetTimeout. */
|
||||
const struct timeval *command_timeout;
|
||||
union {
|
||||
/** use this field for tcp/ip connections */
|
||||
struct {
|
||||
const char *source_addr;
|
||||
const char *ip;
|
||||
int port;
|
||||
} tcp;
|
||||
/** use this field for unix domain sockets */
|
||||
const char *unix_socket;
|
||||
/**
|
||||
* use this field to have hiredis operate an already-open
|
||||
* file descriptor */
|
||||
redisFD fd;
|
||||
} endpoint;
|
||||
|
||||
/* Optional user defined data/destructor */
|
||||
void *privdata;
|
||||
void (*free_privdata)(void *);
|
||||
|
||||
/* A user defined PUSH message callback */
|
||||
redisPushFn *push_cb;
|
||||
redisAsyncPushFn *async_push_cb;
|
||||
} redisOptions;
|
||||
|
||||
/**
|
||||
* Helper macros to initialize options to their specified fields.
|
||||
*/
|
||||
#define REDIS_OPTIONS_SET_TCP(opts, ip_, port_) \
|
||||
(opts)->type = REDIS_CONN_TCP; \
|
||||
(opts)->endpoint.tcp.ip = ip_; \
|
||||
(opts)->endpoint.tcp.port = port_;
|
||||
|
||||
#define REDIS_OPTIONS_SET_UNIX(opts, path) \
|
||||
(opts)->type = REDIS_CONN_UNIX; \
|
||||
(opts)->endpoint.unix_socket = path;
|
||||
|
||||
#define REDIS_OPTIONS_SET_PRIVDATA(opts, data, dtor) \
|
||||
(opts)->privdata = data; \
|
||||
(opts)->free_privdata = dtor; \
|
||||
|
||||
typedef struct redisContextFuncs {
|
||||
void (*free_privctx)(void *);
|
||||
void (*async_read)(struct redisAsyncContext *);
|
||||
void (*async_write)(struct redisAsyncContext *);
|
||||
ssize_t (*read)(struct redisContext *, char *, size_t);
|
||||
ssize_t (*write)(struct redisContext *);
|
||||
} redisContextFuncs;
|
||||
|
||||
/* Context for a connection to Redis */
|
||||
typedef struct redisContext {
|
||||
const redisContextFuncs *funcs; /* Function table */
|
||||
|
||||
int err; /* Error flags, 0 when there is no error */
|
||||
char errstr[128]; /* String representation of error when applicable */
|
||||
redisFD fd;
|
||||
int flags;
|
||||
char *obuf; /* Write buffer */
|
||||
redisReader *reader; /* Protocol reader */
|
||||
|
||||
enum redisConnectionType connection_type;
|
||||
struct timeval *connect_timeout;
|
||||
struct timeval *command_timeout;
|
||||
|
||||
struct {
|
||||
char *host;
|
||||
char *source_addr;
|
||||
int port;
|
||||
} tcp;
|
||||
|
||||
struct {
|
||||
char *path;
|
||||
} unix_sock;
|
||||
|
||||
/* For non-blocking connect */
|
||||
struct sockaddr *saddr;
|
||||
size_t addrlen;
|
||||
|
||||
/* Optional data and corresponding destructor users can use to provide
|
||||
* context to a given redisContext. Not used by hiredis. */
|
||||
void *privdata;
|
||||
void (*free_privdata)(void *);
|
||||
|
||||
/* Internal context pointer presently used by hiredis to manage
|
||||
* SSL connections. */
|
||||
void *privctx;
|
||||
|
||||
/* An optional RESP3 PUSH handler */
|
||||
redisPushFn *push_cb;
|
||||
} redisContext;
|
||||
|
||||
redisContext *redisConnectWithOptions(const redisOptions *options);
|
||||
redisContext *redisConnect(const char *ip, int port);
|
||||
redisContext *redisConnectWithTimeout(const char *ip, int port, const struct timeval tv);
|
||||
redisContext *redisConnectNonBlock(const char *ip, int port);
|
||||
redisContext *redisConnectBindNonBlock(const char *ip, int port,
|
||||
const char *source_addr);
|
||||
redisContext *redisConnectBindNonBlockWithReuse(const char *ip, int port,
|
||||
const char *source_addr);
|
||||
redisContext *redisConnectUnix(const char *path);
|
||||
redisContext *redisConnectUnixWithTimeout(const char *path, const struct timeval tv);
|
||||
redisContext *redisConnectUnixNonBlock(const char *path);
|
||||
redisContext *redisConnectFd(redisFD fd);
|
||||
|
||||
/**
|
||||
* Reconnect the given context using the saved information.
|
||||
*
|
||||
* This re-uses the exact same connect options as in the initial connection.
|
||||
* host, ip (or path), timeout and bind address are reused,
|
||||
* flags are used unmodified from the existing context.
|
||||
*
|
||||
* Returns REDIS_OK on successful connect or REDIS_ERR otherwise.
|
||||
*/
|
||||
int redisReconnect(redisContext *c);
|
||||
|
||||
redisPushFn *redisSetPushCallback(redisContext *c, redisPushFn *fn);
|
||||
int redisSetTimeout(redisContext *c, const struct timeval tv);
|
||||
int redisEnableKeepAlive(redisContext *c);
|
||||
void redisFree(redisContext *c);
|
||||
redisFD redisFreeKeepFd(redisContext *c);
|
||||
int redisBufferRead(redisContext *c);
|
||||
int redisBufferWrite(redisContext *c, int *done);
|
||||
|
||||
/* In a blocking context, this function first checks if there are unconsumed
|
||||
* replies to return and returns one if so. Otherwise, it flushes the output
|
||||
* buffer to the socket and reads until it has a reply. In a non-blocking
|
||||
* context, it will return unconsumed replies until there are no more. */
|
||||
int redisGetReply(redisContext *c, void **reply);
|
||||
int redisGetReplyFromReader(redisContext *c, void **reply);
|
||||
|
||||
/* Write a formatted command to the output buffer. Use these functions in blocking mode
|
||||
* to get a pipeline of commands. */
|
||||
int redisAppendFormattedCommand(redisContext *c, const char *cmd, size_t len);
|
||||
|
||||
/* Write a command to the output buffer. Use these functions in blocking mode
|
||||
* to get a pipeline of commands. */
|
||||
int redisvAppendCommand(redisContext *c, const char *format, va_list ap);
|
||||
int redisAppendCommand(redisContext *c, const char *format, ...);
|
||||
int redisAppendCommandArgv(redisContext *c, int argc, const char **argv, const size_t *argvlen);
|
||||
|
||||
/* Issue a command to Redis. In a blocking context, it is identical to calling
|
||||
* redisAppendCommand, followed by redisGetReply. The function will return
|
||||
* NULL if there was an error in performing the request, otherwise it will
|
||||
* return the reply. In a non-blocking context, it is identical to calling
|
||||
* only redisAppendCommand and will always return NULL. */
|
||||
void *redisvCommand(redisContext *c, const char *format, va_list ap);
|
||||
void *redisCommand(redisContext *c, const char *format, ...);
|
||||
void *redisCommandArgv(redisContext *c, int argc, const char **argv, const size_t *argvlen);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,129 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2009-2011, Salvatore Sanfilippo <antirez at gmail dot com>
|
||||
* Copyright (c) 2010-2011, Pieter Noordhuis <pcnoordhuis at gmail dot com>
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of Redis nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without
|
||||
* specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __HIREDIS_READ_H
|
||||
#define __HIREDIS_READ_H
|
||||
#include <stdio.h> /* for size_t */
|
||||
|
||||
#define REDIS_ERR -1
|
||||
#define REDIS_OK 0
|
||||
|
||||
/* When an error occurs, the err flag in a context is set to hold the type of
|
||||
* error that occurred. REDIS_ERR_IO means there was an I/O error and you
|
||||
* should use the "errno" variable to find out what is wrong.
|
||||
* For other values, the "errstr" field will hold a description. */
|
||||
#define REDIS_ERR_IO 1 /* Error in read or write */
|
||||
#define REDIS_ERR_EOF 3 /* End of file */
|
||||
#define REDIS_ERR_PROTOCOL 4 /* Protocol error */
|
||||
#define REDIS_ERR_OOM 5 /* Out of memory */
|
||||
#define REDIS_ERR_TIMEOUT 6 /* Timed out */
|
||||
#define REDIS_ERR_OTHER 2 /* Everything else... */
|
||||
|
||||
#define REDIS_REPLY_STRING 1
|
||||
#define REDIS_REPLY_ARRAY 2
|
||||
#define REDIS_REPLY_INTEGER 3
|
||||
#define REDIS_REPLY_NIL 4
|
||||
#define REDIS_REPLY_STATUS 5
|
||||
#define REDIS_REPLY_ERROR 6
|
||||
#define REDIS_REPLY_DOUBLE 7
|
||||
#define REDIS_REPLY_BOOL 8
|
||||
#define REDIS_REPLY_MAP 9
|
||||
#define REDIS_REPLY_SET 10
|
||||
#define REDIS_REPLY_ATTR 11
|
||||
#define REDIS_REPLY_PUSH 12
|
||||
#define REDIS_REPLY_BIGNUM 13
|
||||
#define REDIS_REPLY_VERB 14
|
||||
|
||||
/* Default max unused reader buffer. */
|
||||
#define REDIS_READER_MAX_BUF (1024*16)
|
||||
|
||||
/* Default multi-bulk element limit */
|
||||
#define REDIS_READER_MAX_ARRAY_ELEMENTS ((1LL<<32) - 1)
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct redisReadTask {
|
||||
int type;
|
||||
long long elements; /* number of elements in multibulk container */
|
||||
int idx; /* index in parent (array) object */
|
||||
void *obj; /* holds user-generated value for a read task */
|
||||
struct redisReadTask *parent; /* parent task */
|
||||
void *privdata; /* user-settable arbitrary field */
|
||||
} redisReadTask;
|
||||
|
||||
typedef struct redisReplyObjectFunctions {
|
||||
void *(*createString)(const redisReadTask*, char*, size_t);
|
||||
void *(*createArray)(const redisReadTask*, size_t);
|
||||
void *(*createInteger)(const redisReadTask*, long long);
|
||||
void *(*createDouble)(const redisReadTask*, double, char*, size_t);
|
||||
void *(*createNil)(const redisReadTask*);
|
||||
void *(*createBool)(const redisReadTask*, int);
|
||||
void (*freeObject)(void*);
|
||||
} redisReplyObjectFunctions;
|
||||
|
||||
typedef struct redisReader {
|
||||
int err; /* Error flags, 0 when there is no error */
|
||||
char errstr[128]; /* String representation of error when applicable */
|
||||
|
||||
char *buf; /* Read buffer */
|
||||
size_t pos; /* Buffer cursor */
|
||||
size_t len; /* Buffer length */
|
||||
size_t maxbuf; /* Max length of unused buffer */
|
||||
long long maxelements; /* Max multi-bulk elements */
|
||||
|
||||
redisReadTask **task;
|
||||
int tasks;
|
||||
|
||||
int ridx; /* Index of current read task */
|
||||
void *reply; /* Temporary reply pointer */
|
||||
|
||||
redisReplyObjectFunctions *fn;
|
||||
void *privdata;
|
||||
} redisReader;
|
||||
|
||||
/* Public API for the protocol parser. */
|
||||
redisReader *redisReaderCreateWithFunctions(redisReplyObjectFunctions *fn);
|
||||
void redisReaderFree(redisReader *r);
|
||||
int redisReaderFeed(redisReader *r, const char *buf, size_t len);
|
||||
int redisReaderGetReply(redisReader *r, void **reply);
|
||||
|
||||
#define redisReaderSetPrivdata(_r, _p) (int)(((redisReader*)(_r))->privdata = (_p))
|
||||
#define redisReaderGetObject(_r) (((redisReader*)(_r))->reply)
|
||||
#define redisReaderGetError(_r) (((redisReader*)(_r))->errstr)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,278 +0,0 @@
|
||||
/* SDSLib 2.0 -- A C dynamic strings library
|
||||
*
|
||||
* Copyright (c) 2006-2015, Salvatore Sanfilippo <antirez at gmail dot com>
|
||||
* Copyright (c) 2015, Oran Agra
|
||||
* Copyright (c) 2015, Redis Labs, Inc
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of Redis nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without
|
||||
* specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef __SDS_H
|
||||
#define __SDS_H
|
||||
|
||||
#define SDS_MAX_PREALLOC (1024*1024)
|
||||
#ifdef _MSC_VER
|
||||
#define __attribute__(x)
|
||||
typedef long long ssize_t;
|
||||
#define SSIZE_MAX (LLONG_MAX >> 1)
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdint.h>
|
||||
|
||||
typedef char *sds;
|
||||
|
||||
/* Note: sdshdr5 is never used, we just access the flags byte directly.
|
||||
* However is here to document the layout of type 5 SDS strings. */
|
||||
struct __attribute__ ((__packed__)) sdshdr5 {
|
||||
unsigned char flags; /* 3 lsb of type, and 5 msb of string length */
|
||||
char buf[];
|
||||
};
|
||||
struct __attribute__ ((__packed__)) sdshdr8 {
|
||||
uint8_t len; /* used */
|
||||
uint8_t alloc; /* excluding the header and null terminator */
|
||||
unsigned char flags; /* 3 lsb of type, 5 unused bits */
|
||||
char buf[];
|
||||
};
|
||||
struct __attribute__ ((__packed__)) sdshdr16 {
|
||||
uint16_t len; /* used */
|
||||
uint16_t alloc; /* excluding the header and null terminator */
|
||||
unsigned char flags; /* 3 lsb of type, 5 unused bits */
|
||||
char buf[];
|
||||
};
|
||||
struct __attribute__ ((__packed__)) sdshdr32 {
|
||||
uint32_t len; /* used */
|
||||
uint32_t alloc; /* excluding the header and null terminator */
|
||||
unsigned char flags; /* 3 lsb of type, 5 unused bits */
|
||||
char buf[];
|
||||
};
|
||||
struct __attribute__ ((__packed__)) sdshdr64 {
|
||||
uint64_t len; /* used */
|
||||
uint64_t alloc; /* excluding the header and null terminator */
|
||||
unsigned char flags; /* 3 lsb of type, 5 unused bits */
|
||||
char buf[];
|
||||
};
|
||||
|
||||
#define SDS_TYPE_5 0
|
||||
#define SDS_TYPE_8 1
|
||||
#define SDS_TYPE_16 2
|
||||
#define SDS_TYPE_32 3
|
||||
#define SDS_TYPE_64 4
|
||||
#define SDS_TYPE_MASK 7
|
||||
#define SDS_TYPE_BITS 3
|
||||
#define SDS_HDR_VAR(T,s) struct sdshdr##T *sh = (struct sdshdr##T *)((s)-(sizeof(struct sdshdr##T)));
|
||||
#define SDS_HDR(T,s) ((struct sdshdr##T *)((s)-(sizeof(struct sdshdr##T))))
|
||||
#define SDS_TYPE_5_LEN(f) ((f)>>SDS_TYPE_BITS)
|
||||
|
||||
static inline size_t sdslen(const sds s) {
|
||||
unsigned char flags = s[-1];
|
||||
switch(flags&SDS_TYPE_MASK) {
|
||||
case SDS_TYPE_5:
|
||||
return SDS_TYPE_5_LEN(flags);
|
||||
case SDS_TYPE_8:
|
||||
return SDS_HDR(8,s)->len;
|
||||
case SDS_TYPE_16:
|
||||
return SDS_HDR(16,s)->len;
|
||||
case SDS_TYPE_32:
|
||||
return SDS_HDR(32,s)->len;
|
||||
case SDS_TYPE_64:
|
||||
return SDS_HDR(64,s)->len;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline size_t sdsavail(const sds s) {
|
||||
unsigned char flags = s[-1];
|
||||
switch(flags&SDS_TYPE_MASK) {
|
||||
case SDS_TYPE_5: {
|
||||
return 0;
|
||||
}
|
||||
case SDS_TYPE_8: {
|
||||
SDS_HDR_VAR(8,s);
|
||||
return sh->alloc - sh->len;
|
||||
}
|
||||
case SDS_TYPE_16: {
|
||||
SDS_HDR_VAR(16,s);
|
||||
return sh->alloc - sh->len;
|
||||
}
|
||||
case SDS_TYPE_32: {
|
||||
SDS_HDR_VAR(32,s);
|
||||
return sh->alloc - sh->len;
|
||||
}
|
||||
case SDS_TYPE_64: {
|
||||
SDS_HDR_VAR(64,s);
|
||||
return sh->alloc - sh->len;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline void sdssetlen(sds s, size_t newlen) {
|
||||
unsigned char flags = s[-1];
|
||||
switch(flags&SDS_TYPE_MASK) {
|
||||
case SDS_TYPE_5:
|
||||
{
|
||||
unsigned char *fp = ((unsigned char*)s)-1;
|
||||
*fp = (unsigned char)(SDS_TYPE_5 | (newlen << SDS_TYPE_BITS));
|
||||
}
|
||||
break;
|
||||
case SDS_TYPE_8:
|
||||
SDS_HDR(8,s)->len = (uint8_t)newlen;
|
||||
break;
|
||||
case SDS_TYPE_16:
|
||||
SDS_HDR(16,s)->len = (uint16_t)newlen;
|
||||
break;
|
||||
case SDS_TYPE_32:
|
||||
SDS_HDR(32,s)->len = (uint32_t)newlen;
|
||||
break;
|
||||
case SDS_TYPE_64:
|
||||
SDS_HDR(64,s)->len = (uint64_t)newlen;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static inline void sdsinclen(sds s, size_t inc) {
|
||||
unsigned char flags = s[-1];
|
||||
switch(flags&SDS_TYPE_MASK) {
|
||||
case SDS_TYPE_5:
|
||||
{
|
||||
unsigned char *fp = ((unsigned char*)s)-1;
|
||||
unsigned char newlen = SDS_TYPE_5_LEN(flags)+(unsigned char)inc;
|
||||
*fp = SDS_TYPE_5 | (newlen << SDS_TYPE_BITS);
|
||||
}
|
||||
break;
|
||||
case SDS_TYPE_8:
|
||||
SDS_HDR(8,s)->len += (uint8_t)inc;
|
||||
break;
|
||||
case SDS_TYPE_16:
|
||||
SDS_HDR(16,s)->len += (uint16_t)inc;
|
||||
break;
|
||||
case SDS_TYPE_32:
|
||||
SDS_HDR(32,s)->len += (uint32_t)inc;
|
||||
break;
|
||||
case SDS_TYPE_64:
|
||||
SDS_HDR(64,s)->len += (uint64_t)inc;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* sdsalloc() = sdsavail() + sdslen() */
|
||||
static inline size_t sdsalloc(const sds s) {
|
||||
unsigned char flags = s[-1];
|
||||
switch(flags&SDS_TYPE_MASK) {
|
||||
case SDS_TYPE_5:
|
||||
return SDS_TYPE_5_LEN(flags);
|
||||
case SDS_TYPE_8:
|
||||
return SDS_HDR(8,s)->alloc;
|
||||
case SDS_TYPE_16:
|
||||
return SDS_HDR(16,s)->alloc;
|
||||
case SDS_TYPE_32:
|
||||
return SDS_HDR(32,s)->alloc;
|
||||
case SDS_TYPE_64:
|
||||
return SDS_HDR(64,s)->alloc;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline void sdssetalloc(sds s, size_t newlen) {
|
||||
unsigned char flags = s[-1];
|
||||
switch(flags&SDS_TYPE_MASK) {
|
||||
case SDS_TYPE_5:
|
||||
/* Nothing to do, this type has no total allocation info. */
|
||||
break;
|
||||
case SDS_TYPE_8:
|
||||
SDS_HDR(8,s)->alloc = (uint8_t)newlen;
|
||||
break;
|
||||
case SDS_TYPE_16:
|
||||
SDS_HDR(16,s)->alloc = (uint16_t)newlen;
|
||||
break;
|
||||
case SDS_TYPE_32:
|
||||
SDS_HDR(32,s)->alloc = (uint32_t)newlen;
|
||||
break;
|
||||
case SDS_TYPE_64:
|
||||
SDS_HDR(64,s)->alloc = (uint64_t)newlen;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
sds sdsnewlen(const void *init, size_t initlen);
|
||||
sds sdsnew(const char *init);
|
||||
sds sdsempty(void);
|
||||
sds sdsdup(const sds s);
|
||||
void sdsfree(sds s);
|
||||
sds sdsgrowzero(sds s, size_t len);
|
||||
sds sdscatlen(sds s, const void *t, size_t len);
|
||||
sds sdscat(sds s, const char *t);
|
||||
sds sdscatsds(sds s, const sds t);
|
||||
sds sdscpylen(sds s, const char *t, size_t len);
|
||||
sds sdscpy(sds s, const char *t);
|
||||
|
||||
sds sdscatvprintf(sds s, const char *fmt, va_list ap);
|
||||
#ifdef __GNUC__
|
||||
sds sdscatprintf(sds s, const char *fmt, ...)
|
||||
__attribute__((format(printf, 2, 3)));
|
||||
#else
|
||||
sds sdscatprintf(sds s, const char *fmt, ...);
|
||||
#endif
|
||||
|
||||
sds sdscatfmt(sds s, char const *fmt, ...);
|
||||
sds sdstrim(sds s, const char *cset);
|
||||
int sdsrange(sds s, ssize_t start, ssize_t end);
|
||||
void sdsupdatelen(sds s);
|
||||
void sdsclear(sds s);
|
||||
int sdscmp(const sds s1, const sds s2);
|
||||
sds *sdssplitlen(const char *s, int len, const char *sep, int seplen, int *count);
|
||||
void sdsfreesplitres(sds *tokens, int count);
|
||||
void sdstolower(sds s);
|
||||
void sdstoupper(sds s);
|
||||
sds sdsfromlonglong(long long value);
|
||||
sds sdscatrepr(sds s, const char *p, size_t len);
|
||||
sds *sdssplitargs(const char *line, int *argc);
|
||||
sds sdsmapchars(sds s, const char *from, const char *to, size_t setlen);
|
||||
sds sdsjoin(char **argv, int argc, char *sep);
|
||||
sds sdsjoinsds(sds *argv, int argc, const char *sep, size_t seplen);
|
||||
|
||||
/* Low level functions exposed to the user API */
|
||||
sds sdsMakeRoomFor(sds s, size_t addlen);
|
||||
void sdsIncrLen(sds s, int incr);
|
||||
sds sdsRemoveFreeSpace(sds s);
|
||||
size_t sdsAllocSize(sds s);
|
||||
void *sdsAllocPtr(sds s);
|
||||
|
||||
/* Export the allocator used by SDS to the program using SDS.
|
||||
* Sometimes the program SDS is linked to, may use a different set of
|
||||
* allocators, but may want to allocate or free things that SDS will
|
||||
* respectively free or allocate. */
|
||||
void *sds_malloc(size_t size);
|
||||
void *sds_realloc(void *ptr, size_t size);
|
||||
void sds_free(void *ptr);
|
||||
|
||||
#ifdef REDIS_TEST
|
||||
int sdsTest(int argc, char *argv[]);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,177 +0,0 @@
|
||||
/* aes.h
|
||||
|
||||
The aes/rijndael block cipher.
|
||||
|
||||
Copyright (C) 2001, 2013 Niels Möller
|
||||
|
||||
This file is part of GNU Nettle.
|
||||
|
||||
GNU Nettle is free software: you can redistribute it and/or
|
||||
modify it under the terms of either:
|
||||
|
||||
* the GNU Lesser General Public License as published by the Free
|
||||
Software Foundation; either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or
|
||||
|
||||
* the GNU General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or both in parallel, as here.
|
||||
|
||||
GNU Nettle is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received copies of the GNU General Public License and
|
||||
the GNU Lesser General Public License along with this program. If
|
||||
not, see http://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
#ifndef NETTLE_AES_H_INCLUDED
|
||||
#define NETTLE_AES_H_INCLUDED
|
||||
|
||||
#include "nettle-types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Name mangling */
|
||||
#define aes_set_encrypt_key nettle_aes_set_encrypt_key
|
||||
#define aes_set_decrypt_key nettle_aes_set_decrypt_key
|
||||
#define aes_invert_key nettle_aes_invert_key
|
||||
#define aes_encrypt nettle_aes_encrypt
|
||||
#define aes_decrypt nettle_aes_decrypt
|
||||
#define aes128_set_encrypt_key nettle_aes128_set_encrypt_key
|
||||
#define aes128_set_decrypt_key nettle_aes128_set_decrypt_key
|
||||
#define aes128_invert_key nettle_aes128_invert_key
|
||||
#define aes128_encrypt nettle_aes128_encrypt
|
||||
#define aes128_decrypt nettle_aes128_decrypt
|
||||
#define aes192_set_encrypt_key nettle_aes192_set_encrypt_key
|
||||
#define aes192_set_decrypt_key nettle_aes192_set_decrypt_key
|
||||
#define aes192_invert_key nettle_aes192_invert_key
|
||||
#define aes192_encrypt nettle_aes192_encrypt
|
||||
#define aes192_decrypt nettle_aes192_decrypt
|
||||
#define aes256_set_encrypt_key nettle_aes256_set_encrypt_key
|
||||
#define aes256_set_decrypt_key nettle_aes256_set_decrypt_key
|
||||
#define aes256_invert_key nettle_aes256_invert_key
|
||||
#define aes256_encrypt nettle_aes256_encrypt
|
||||
#define aes256_decrypt nettle_aes256_decrypt
|
||||
|
||||
#define AES_BLOCK_SIZE 16
|
||||
|
||||
#define AES128_KEY_SIZE 16
|
||||
#define AES192_KEY_SIZE 24
|
||||
#define AES256_KEY_SIZE 32
|
||||
#define _AES128_ROUNDS 10
|
||||
#define _AES192_ROUNDS 12
|
||||
#define _AES256_ROUNDS 14
|
||||
|
||||
/* Variable key size between 128 and 256 bits. But the only valid
|
||||
* values are 16 (128 bits), 24 (192 bits) and 32 (256 bits). */
|
||||
#define AES_MIN_KEY_SIZE AES128_KEY_SIZE
|
||||
#define AES_MAX_KEY_SIZE AES256_KEY_SIZE
|
||||
|
||||
/* Older nettle-2.7 interface */
|
||||
|
||||
#define AES_KEY_SIZE 32
|
||||
|
||||
struct aes_ctx
|
||||
{
|
||||
unsigned rounds; /* number of rounds to use for our key size */
|
||||
uint32_t keys[4*(_AES256_ROUNDS + 1)]; /* maximum size of key schedule */
|
||||
};
|
||||
|
||||
void
|
||||
aes_set_encrypt_key(struct aes_ctx *ctx,
|
||||
size_t length, const uint8_t *key);
|
||||
|
||||
void
|
||||
aes_set_decrypt_key(struct aes_ctx *ctx,
|
||||
size_t length, const uint8_t *key);
|
||||
|
||||
void
|
||||
aes_invert_key(struct aes_ctx *dst,
|
||||
const struct aes_ctx *src);
|
||||
|
||||
void
|
||||
aes_encrypt(const struct aes_ctx *ctx,
|
||||
size_t length, uint8_t *dst,
|
||||
const uint8_t *src);
|
||||
void
|
||||
aes_decrypt(const struct aes_ctx *ctx,
|
||||
size_t length, uint8_t *dst,
|
||||
const uint8_t *src);
|
||||
|
||||
struct aes128_ctx
|
||||
{
|
||||
uint32_t keys[4 * (_AES128_ROUNDS + 1)];
|
||||
};
|
||||
|
||||
void
|
||||
aes128_set_encrypt_key(struct aes128_ctx *ctx, const uint8_t *key);
|
||||
void
|
||||
aes128_set_decrypt_key(struct aes128_ctx *ctx, const uint8_t *key);
|
||||
void
|
||||
aes128_invert_key(struct aes128_ctx *dst,
|
||||
const struct aes128_ctx *src);
|
||||
void
|
||||
aes128_encrypt(const struct aes128_ctx *ctx,
|
||||
size_t length, uint8_t *dst,
|
||||
const uint8_t *src);
|
||||
void
|
||||
aes128_decrypt(const struct aes128_ctx *ctx,
|
||||
size_t length, uint8_t *dst,
|
||||
const uint8_t *src);
|
||||
|
||||
struct aes192_ctx
|
||||
{
|
||||
uint32_t keys[4 * (_AES192_ROUNDS + 1)];
|
||||
};
|
||||
|
||||
void
|
||||
aes192_set_encrypt_key(struct aes192_ctx *ctx, const uint8_t *key);
|
||||
void
|
||||
aes192_set_decrypt_key(struct aes192_ctx *ctx, const uint8_t *key);
|
||||
void
|
||||
aes192_invert_key(struct aes192_ctx *dst,
|
||||
const struct aes192_ctx *src);
|
||||
void
|
||||
aes192_encrypt(const struct aes192_ctx *ctx,
|
||||
size_t length, uint8_t *dst,
|
||||
const uint8_t *src);
|
||||
void
|
||||
aes192_decrypt(const struct aes192_ctx *ctx,
|
||||
size_t length, uint8_t *dst,
|
||||
const uint8_t *src);
|
||||
|
||||
struct aes256_ctx
|
||||
{
|
||||
uint32_t keys[4 * (_AES256_ROUNDS + 1)];
|
||||
};
|
||||
|
||||
void
|
||||
aes256_set_encrypt_key(struct aes256_ctx *ctx, const uint8_t *key);
|
||||
void
|
||||
aes256_set_decrypt_key(struct aes256_ctx *ctx, const uint8_t *key);
|
||||
void
|
||||
aes256_invert_key(struct aes256_ctx *dst,
|
||||
const struct aes256_ctx *src);
|
||||
void
|
||||
aes256_encrypt(const struct aes256_ctx *ctx,
|
||||
size_t length, uint8_t *dst,
|
||||
const uint8_t *src);
|
||||
void
|
||||
aes256_decrypt(const struct aes256_ctx *ctx,
|
||||
size_t length, uint8_t *dst,
|
||||
const uint8_t *src);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* NETTLE_AES_H_INCLUDED */
|
||||
@@ -1,79 +0,0 @@
|
||||
/* arcfour.h
|
||||
|
||||
The arcfour/rc4 stream cipher.
|
||||
|
||||
Copyright (C) 2001, 2014 Niels Möller
|
||||
|
||||
This file is part of GNU Nettle.
|
||||
|
||||
GNU Nettle is free software: you can redistribute it and/or
|
||||
modify it under the terms of either:
|
||||
|
||||
* the GNU Lesser General Public License as published by the Free
|
||||
Software Foundation; either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or
|
||||
|
||||
* the GNU General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or both in parallel, as here.
|
||||
|
||||
GNU Nettle is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received copies of the GNU General Public License and
|
||||
the GNU Lesser General Public License along with this program. If
|
||||
not, see http://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
#ifndef NETTLE_ARCFOUR_H_INCLUDED
|
||||
#define NETTLE_ARCFOUR_H_INCLUDED
|
||||
|
||||
#include "nettle-types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Name mangling */
|
||||
#define arcfour128_set_key nettle_arcfour128_set_key
|
||||
#define arcfour_set_key nettle_arcfour_set_key
|
||||
#define arcfour_crypt nettle_arcfour_crypt
|
||||
|
||||
/* Minimum and maximum keysizes, and a reasonable default. In
|
||||
* octets.*/
|
||||
#define ARCFOUR_MIN_KEY_SIZE 1
|
||||
#define ARCFOUR_MAX_KEY_SIZE 256
|
||||
#define ARCFOUR_KEY_SIZE 16
|
||||
#define ARCFOUR128_KEY_SIZE 16
|
||||
|
||||
struct arcfour_ctx
|
||||
{
|
||||
uint8_t S[256];
|
||||
uint8_t i;
|
||||
uint8_t j;
|
||||
};
|
||||
|
||||
void
|
||||
arcfour_set_key(struct arcfour_ctx *ctx,
|
||||
size_t length, const uint8_t *key);
|
||||
|
||||
void
|
||||
arcfour128_set_key(struct arcfour_ctx *ctx, const uint8_t *key);
|
||||
|
||||
void
|
||||
arcfour_crypt(struct arcfour_ctx *ctx,
|
||||
size_t length, uint8_t *dst,
|
||||
const uint8_t *src);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* NETTLE_ARCFOUR_H_INCLUDED */
|
||||
|
||||
@@ -1,103 +0,0 @@
|
||||
/* arctwo.h
|
||||
|
||||
The arctwo/rfc2268 block cipher.
|
||||
|
||||
Copyright (C) 2004 Simon Josefsson
|
||||
Copyright (C) 2002, 2004, 2014 Niels Möller
|
||||
|
||||
This file is part of GNU Nettle.
|
||||
|
||||
GNU Nettle is free software: you can redistribute it and/or
|
||||
modify it under the terms of either:
|
||||
|
||||
* the GNU Lesser General Public License as published by the Free
|
||||
Software Foundation; either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or
|
||||
|
||||
* the GNU General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or both in parallel, as here.
|
||||
|
||||
GNU Nettle is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received copies of the GNU General Public License and
|
||||
the GNU Lesser General Public License along with this program. If
|
||||
not, see http://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
#ifndef NETTLE_ARCTWO_H_INCLUDED
|
||||
#define NETTLE_ARCTWO_H_INCLUDED
|
||||
|
||||
#include "nettle-types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Name mangling */
|
||||
#define arctwo_set_key nettle_arctwo_set_key
|
||||
#define arctwo_set_key_ekb nettle_arctwo_set_key_ekb
|
||||
#define arctwo_set_key_gutmann nettle_arctwo_set_key_gutmann
|
||||
#define arctwo40_set_key nettle_arctwo40_set_key
|
||||
#define arctwo64_set_key nettle_arctwo64_set_key
|
||||
#define arctwo128_set_key nettle_arctwo128_set_key
|
||||
#define arctwo128_set_key_gutmann nettle_arctwo128_set_key_gutmann
|
||||
#define arctwo_encrypt nettle_arctwo_encrypt
|
||||
#define arctwo_decrypt nettle_arctwo_decrypt
|
||||
|
||||
#define ARCTWO_BLOCK_SIZE 8
|
||||
|
||||
/* Variable key size from 1 byte to 128 bytes. */
|
||||
#define ARCTWO_MIN_KEY_SIZE 1
|
||||
#define ARCTWO_MAX_KEY_SIZE 128
|
||||
|
||||
#define ARCTWO_KEY_SIZE 8
|
||||
|
||||
struct arctwo_ctx
|
||||
{
|
||||
uint16_t S[64];
|
||||
};
|
||||
|
||||
/* Key expansion function that takes the "effective key bits", 1-1024,
|
||||
as an explicit argument. 0 means maximum key bits. */
|
||||
void
|
||||
arctwo_set_key_ekb (struct arctwo_ctx *ctx,
|
||||
size_t length, const uint8_t * key, unsigned ekb);
|
||||
|
||||
/* Equvivalent to arctwo_set_key_ekb, with ekb = 8 * length */
|
||||
void
|
||||
arctwo_set_key (struct arctwo_ctx *ctx, size_t length, const uint8_t *key);
|
||||
void
|
||||
arctwo40_set_key (struct arctwo_ctx *ctx, const uint8_t *key);
|
||||
void
|
||||
arctwo64_set_key (struct arctwo_ctx *ctx, const uint8_t *key);
|
||||
void
|
||||
arctwo128_set_key (struct arctwo_ctx *ctx, const uint8_t *key);
|
||||
|
||||
/* Equvivalent to arctwo_set_key_ekb, with ekb = 1024 */
|
||||
void
|
||||
arctwo_set_key_gutmann (struct arctwo_ctx *ctx,
|
||||
size_t length, const uint8_t *key);
|
||||
void
|
||||
arctwo128_set_key_gutmann (struct arctwo_ctx *ctx,
|
||||
const uint8_t *key);
|
||||
|
||||
void
|
||||
arctwo_encrypt (struct arctwo_ctx *ctx,
|
||||
size_t length, uint8_t *dst, const uint8_t *src);
|
||||
void
|
||||
arctwo_decrypt (struct arctwo_ctx *ctx,
|
||||
size_t length, uint8_t *dst, const uint8_t *src);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* NETTLE_ARCTWO_H_INCLUDED */
|
||||
@@ -1,152 +0,0 @@
|
||||
/* asn1.h
|
||||
|
||||
Limited support for ASN.1 DER decoding.
|
||||
|
||||
Copyright (C) 2005 Niels Möller
|
||||
|
||||
This file is part of GNU Nettle.
|
||||
|
||||
GNU Nettle is free software: you can redistribute it and/or
|
||||
modify it under the terms of either:
|
||||
|
||||
* the GNU Lesser General Public License as published by the Free
|
||||
Software Foundation; either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or
|
||||
|
||||
* the GNU General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or both in parallel, as here.
|
||||
|
||||
GNU Nettle is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received copies of the GNU General Public License and
|
||||
the GNU Lesser General Public License along with this program. If
|
||||
not, see http://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
#ifndef NETTLE_ASN1_H_INCLUDED
|
||||
#define NETTLE_ASN1_H_INCLUDED
|
||||
|
||||
#include "nettle-types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Name mangling */
|
||||
#define asn1_der_iterator_first nettle_asn1_der_iterator_first
|
||||
#define asn1_der_iterator_next nettle_asn1_der_iterator_next
|
||||
#define asn1_der_decode_constructed nettle_asn1_der_decode_constructed
|
||||
#define asn1_der_decode_constructed_last nettle_asn1_der_decode_constructed_last
|
||||
#define asn1_der_decode_bitstring nettle_asn1_der_decode_bitstring
|
||||
#define asn1_der_decode_bitstring_last nettle_asn1_der_decode_bitstring_last
|
||||
#define asn1_der_get_uint32 nettle_asn1_der_get_uint32
|
||||
#define asn1_der_get_bignum nettle_asn1_der_get_bignum
|
||||
|
||||
|
||||
/* enum asn1_type keeps the class number and the constructive in bits
|
||||
13-14, and the constructive flag in bit 12. The remaining 14 bits
|
||||
are the tag (although currently, only tags in the range 0-30 are
|
||||
supported). */
|
||||
|
||||
enum
|
||||
{
|
||||
ASN1_TYPE_CONSTRUCTED = 1 << 12,
|
||||
|
||||
ASN1_CLASS_UNIVERSAL = 0,
|
||||
ASN1_CLASS_APPLICATION = 1 << 13,
|
||||
ASN1_CLASS_CONTEXT_SPECIFIC = 2 << 13,
|
||||
ASN1_CLASS_PRIVATE = 3 << 13,
|
||||
|
||||
ASN1_CLASS_MASK = 3 << 13,
|
||||
ASN1_CLASS_SHIFT = 13,
|
||||
};
|
||||
|
||||
enum asn1_type
|
||||
{
|
||||
ASN1_BOOLEAN = 1,
|
||||
ASN1_INTEGER = 2,
|
||||
ASN1_BITSTRING = 3,
|
||||
ASN1_OCTETSTRING = 4,
|
||||
ASN1_NULL = 5,
|
||||
ASN1_IDENTIFIER = 6,
|
||||
ASN1_REAL = 9,
|
||||
ASN1_ENUMERATED = 10,
|
||||
ASN1_UTF8STRING = 12,
|
||||
ASN1_SEQUENCE = 16 | ASN1_TYPE_CONSTRUCTED,
|
||||
ASN1_SET = 17 | ASN1_TYPE_CONSTRUCTED,
|
||||
ASN1_PRINTABLESTRING = 19,
|
||||
ASN1_TELETEXSTRING = 20,
|
||||
ASN1_IA5STRING = 22,
|
||||
ASN1_UTC = 23,
|
||||
ASN1_UNIVERSALSTRING = 28,
|
||||
ASN1_BMPSTRING = 30,
|
||||
};
|
||||
|
||||
enum asn1_iterator_result
|
||||
{
|
||||
ASN1_ITERATOR_ERROR,
|
||||
ASN1_ITERATOR_PRIMITIVE,
|
||||
ASN1_ITERATOR_CONSTRUCTED,
|
||||
ASN1_ITERATOR_END,
|
||||
};
|
||||
|
||||
/* Parsing DER objects. */
|
||||
struct asn1_der_iterator
|
||||
{
|
||||
size_t buffer_length;
|
||||
const uint8_t *buffer;
|
||||
|
||||
/* Next object to parse. */
|
||||
size_t pos;
|
||||
|
||||
enum asn1_type type;
|
||||
|
||||
/* Pointer to the current object */
|
||||
size_t length;
|
||||
const uint8_t *data;
|
||||
};
|
||||
|
||||
/* Initializes the iterator. */
|
||||
enum asn1_iterator_result
|
||||
asn1_der_iterator_first(struct asn1_der_iterator *iterator,
|
||||
size_t length, const uint8_t *input);
|
||||
|
||||
enum asn1_iterator_result
|
||||
asn1_der_iterator_next(struct asn1_der_iterator *iterator);
|
||||
|
||||
/* Starts parsing of a constructed object. */
|
||||
enum asn1_iterator_result
|
||||
asn1_der_decode_constructed(struct asn1_der_iterator *i,
|
||||
struct asn1_der_iterator *contents);
|
||||
|
||||
/* For the common case that we have a sequence at the end of the
|
||||
object. Checks that the current object is the final one, and then
|
||||
reinitializes the iterator to parse its ontents. */
|
||||
enum asn1_iterator_result
|
||||
asn1_der_decode_constructed_last(struct asn1_der_iterator *i);
|
||||
|
||||
enum asn1_iterator_result
|
||||
asn1_der_decode_bitstring(struct asn1_der_iterator *i,
|
||||
struct asn1_der_iterator *contents);
|
||||
|
||||
enum asn1_iterator_result
|
||||
asn1_der_decode_bitstring_last(struct asn1_der_iterator *i);
|
||||
|
||||
/* All these functions return 1 on success, 0 on failure */
|
||||
int
|
||||
asn1_der_get_uint32(struct asn1_der_iterator *i,
|
||||
uint32_t *x);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* NETTLE_ASN1_H_INCLUDED */
|
||||
@@ -1,110 +0,0 @@
|
||||
/* base16.h
|
||||
|
||||
Hex encoding and decoding, following spki conventions (i.e.
|
||||
allowing whitespace between digits).
|
||||
|
||||
Copyright (C) 2002 Niels Möller
|
||||
|
||||
This file is part of GNU Nettle.
|
||||
|
||||
GNU Nettle is free software: you can redistribute it and/or
|
||||
modify it under the terms of either:
|
||||
|
||||
* the GNU Lesser General Public License as published by the Free
|
||||
Software Foundation; either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or
|
||||
|
||||
* the GNU General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or both in parallel, as here.
|
||||
|
||||
GNU Nettle is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received copies of the GNU General Public License and
|
||||
the GNU Lesser General Public License along with this program. If
|
||||
not, see http://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
#ifndef NETTLE_BASE16_H_INCLUDED
|
||||
#define NETTLE_BASE16_H_INCLUDED
|
||||
|
||||
#include "nettle-types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Name mangling */
|
||||
#define base16_encode_single nettle_base16_encode_single
|
||||
#define base16_encode_update nettle_base16_encode_update
|
||||
#define base16_decode_init nettle_base16_decode_init
|
||||
#define base16_decode_single nettle_base16_decode_single
|
||||
#define base16_decode_update nettle_base16_decode_update
|
||||
#define base16_decode_final nettle_base16_decode_final
|
||||
|
||||
/* Base16 encoding */
|
||||
|
||||
/* Maximum length of output for base16_encode_update. */
|
||||
#define BASE16_ENCODE_LENGTH(length) ((length) * 2)
|
||||
|
||||
/* Encodes a single byte. Always stores two digits in dst[0] and dst[1]. */
|
||||
void
|
||||
base16_encode_single(char *dst,
|
||||
uint8_t src);
|
||||
|
||||
/* Always stores BASE16_ENCODE_LENGTH(length) digits in dst. */
|
||||
void
|
||||
base16_encode_update(char *dst,
|
||||
size_t length,
|
||||
const uint8_t *src);
|
||||
|
||||
|
||||
/* Base16 decoding */
|
||||
|
||||
/* Maximum length of output for base16_decode_update. */
|
||||
/* We have at most 4 buffered bits, and a total of (length + 1) * 4 bits. */
|
||||
#define BASE16_DECODE_LENGTH(length) (((length) + 1) / 2)
|
||||
|
||||
struct base16_decode_ctx
|
||||
{
|
||||
unsigned char word; /* Leftover bits */
|
||||
unsigned char bits; /* Number buffered bits */
|
||||
};
|
||||
|
||||
void
|
||||
base16_decode_init(struct base16_decode_ctx *ctx);
|
||||
|
||||
/* Decodes a single byte. Returns amount of output (0 or 1), or -1 on
|
||||
* errors. */
|
||||
int
|
||||
base16_decode_single(struct base16_decode_ctx *ctx,
|
||||
uint8_t *dst,
|
||||
char src);
|
||||
|
||||
/* Returns 1 on success, 0 on error. DST should point to an area of
|
||||
* size at least BASE16_DECODE_LENGTH(length). The amount of data
|
||||
* generated is returned in *DST_LENGTH. */
|
||||
|
||||
int
|
||||
base16_decode_update(struct base16_decode_ctx *ctx,
|
||||
size_t *dst_length,
|
||||
uint8_t *dst,
|
||||
size_t src_length,
|
||||
const char *src);
|
||||
|
||||
/* Returns 1 on success. */
|
||||
int
|
||||
base16_decode_final(struct base16_decode_ctx *ctx);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* NETTLE_BASE16_H_INCLUDED */
|
||||
@@ -1,172 +0,0 @@
|
||||
/* base64.h
|
||||
|
||||
Base-64 encoding and decoding.
|
||||
|
||||
Copyright (C) 2002 Niels Möller, Dan Egnor
|
||||
|
||||
This file is part of GNU Nettle.
|
||||
|
||||
GNU Nettle is free software: you can redistribute it and/or
|
||||
modify it under the terms of either:
|
||||
|
||||
* the GNU Lesser General Public License as published by the Free
|
||||
Software Foundation; either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or
|
||||
|
||||
* the GNU General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or both in parallel, as here.
|
||||
|
||||
GNU Nettle is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received copies of the GNU General Public License and
|
||||
the GNU Lesser General Public License along with this program. If
|
||||
not, see http://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
#ifndef NETTLE_BASE64_H_INCLUDED
|
||||
#define NETTLE_BASE64_H_INCLUDED
|
||||
|
||||
#include "nettle-types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Name mangling */
|
||||
#define base64_encode_init nettle_base64_encode_init
|
||||
#define base64url_encode_init nettle_base64url_encode_init
|
||||
#define base64_encode_single nettle_base64_encode_single
|
||||
#define base64_encode_update nettle_base64_encode_update
|
||||
#define base64_encode_final nettle_base64_encode_final
|
||||
#define base64_encode_raw nettle_base64_encode_raw
|
||||
#define base64_encode_group nettle_base64_encode_group
|
||||
#define base64_decode_init nettle_base64_decode_init
|
||||
#define base64url_decode_init nettle_base64url_decode_init
|
||||
#define base64_decode_single nettle_base64_decode_single
|
||||
#define base64_decode_update nettle_base64_decode_update
|
||||
#define base64_decode_final nettle_base64_decode_final
|
||||
|
||||
#define BASE64_BINARY_BLOCK_SIZE 3
|
||||
#define BASE64_TEXT_BLOCK_SIZE 4
|
||||
|
||||
/* Base64 encoding */
|
||||
|
||||
/* Maximum length of output for base64_encode_update. NOTE: Doesn't
|
||||
* include any padding that base64_encode_final may add. */
|
||||
/* We have at most 4 buffered bits, and a total of (4 + length * 8) bits. */
|
||||
#define BASE64_ENCODE_LENGTH(length) (((length) * 8 + 4)/6)
|
||||
|
||||
/* Maximum length of output generated by base64_encode_final. */
|
||||
#define BASE64_ENCODE_FINAL_LENGTH 3
|
||||
|
||||
/* Exact length of output generated by base64_encode_raw, including
|
||||
* padding. */
|
||||
#define BASE64_ENCODE_RAW_LENGTH(length) ((((length) + 2)/3)*4)
|
||||
|
||||
struct base64_encode_ctx
|
||||
{
|
||||
const char *alphabet; /* Alphabet to use for encoding */
|
||||
unsigned short word; /* Leftover bits */
|
||||
unsigned char bits; /* Number of bits, always 0, 2, or 4. */
|
||||
};
|
||||
|
||||
/* Initialize encoding context for base-64 */
|
||||
void
|
||||
base64_encode_init(struct base64_encode_ctx *ctx);
|
||||
|
||||
/* Initialize encoding context for URL safe alphabet, RFC 4648. */
|
||||
void
|
||||
base64url_encode_init(struct base64_encode_ctx *ctx);
|
||||
|
||||
/* Encodes a single byte. Returns amount of output (always 1 or 2). */
|
||||
size_t
|
||||
base64_encode_single(struct base64_encode_ctx *ctx,
|
||||
char *dst,
|
||||
uint8_t src);
|
||||
|
||||
/* Returns the number of output characters. DST should point to an
|
||||
* area of size at least BASE64_ENCODE_LENGTH(length). */
|
||||
size_t
|
||||
base64_encode_update(struct base64_encode_ctx *ctx,
|
||||
char *dst,
|
||||
size_t length,
|
||||
const uint8_t *src);
|
||||
|
||||
/* DST should point to an area of size at least
|
||||
* BASE64_ENCODE_FINAL_LENGTH */
|
||||
size_t
|
||||
base64_encode_final(struct base64_encode_ctx *ctx,
|
||||
char *dst);
|
||||
|
||||
/* Lower level functions */
|
||||
|
||||
/* Encodes a string in one go, including any padding at the end.
|
||||
* Generates exactly BASE64_ENCODE_RAW_LENGTH(length) bytes of output.
|
||||
* Supports overlapped operation, if src <= dst. FIXME: Use of overlap
|
||||
* is deprecated, if needed there should be a separate public fucntion
|
||||
* to do that.*/
|
||||
void
|
||||
base64_encode_raw(char *dst, size_t length, const uint8_t *src);
|
||||
|
||||
void
|
||||
base64_encode_group(char *dst, uint32_t group);
|
||||
|
||||
|
||||
/* Base64 decoding */
|
||||
|
||||
/* Maximum length of output for base64_decode_update. */
|
||||
/* We have at most 6 buffered bits, and a total of (length + 1) * 6 bits. */
|
||||
#define BASE64_DECODE_LENGTH(length) ((((length) + 1) * 6) / 8)
|
||||
|
||||
struct base64_decode_ctx
|
||||
{
|
||||
const signed char *table; /* Decoding table */
|
||||
unsigned short word; /* Leftover bits */
|
||||
unsigned char bits; /* Number buffered bits */
|
||||
|
||||
/* Number of padding characters encountered */
|
||||
unsigned char padding;
|
||||
};
|
||||
|
||||
/* Initialize decoding context for base-64 */
|
||||
void
|
||||
base64_decode_init(struct base64_decode_ctx *ctx);
|
||||
|
||||
/* Initialize encoding context for URL safe alphabet, RFC 4648. */
|
||||
void
|
||||
base64url_decode_init(struct base64_decode_ctx *ctx);
|
||||
|
||||
/* Decodes a single byte. Returns amount of output (0 or 1), or -1 on
|
||||
* errors. */
|
||||
int
|
||||
base64_decode_single(struct base64_decode_ctx *ctx,
|
||||
uint8_t *dst,
|
||||
char src);
|
||||
|
||||
/* Returns 1 on success, 0 on error. DST should point to an area of
|
||||
* size at least BASE64_DECODE_LENGTH(length). The amount of data
|
||||
* generated is returned in *DST_LENGTH. */
|
||||
int
|
||||
base64_decode_update(struct base64_decode_ctx *ctx,
|
||||
size_t *dst_length,
|
||||
uint8_t *dst,
|
||||
size_t src_length,
|
||||
const char *src);
|
||||
|
||||
/* Returns 1 on success. */
|
||||
int
|
||||
base64_decode_final(struct base64_decode_ctx *ctx);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* NETTLE_BASE64_H_INCLUDED */
|
||||
@@ -1,140 +0,0 @@
|
||||
/* bignum.h
|
||||
|
||||
Bignum operations that are missing from gmp.
|
||||
|
||||
Copyright (C) 2001 Niels Möller
|
||||
|
||||
This file is part of GNU Nettle.
|
||||
|
||||
GNU Nettle is free software: you can redistribute it and/or
|
||||
modify it under the terms of either:
|
||||
|
||||
* the GNU Lesser General Public License as published by the Free
|
||||
Software Foundation; either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or
|
||||
|
||||
* the GNU General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or both in parallel, as here.
|
||||
|
||||
GNU Nettle is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received copies of the GNU General Public License and
|
||||
the GNU Lesser General Public License along with this program. If
|
||||
not, see http://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
#ifndef NETTLE_BIGNUM_H_INCLUDED
|
||||
#define NETTLE_BIGNUM_H_INCLUDED
|
||||
|
||||
#include "nettle-meta.h"
|
||||
|
||||
#include "nettle-types.h"
|
||||
|
||||
/* For NETTLE_USE_MINI_GMP */
|
||||
#include "version.h"
|
||||
|
||||
#if NETTLE_USE_MINI_GMP
|
||||
# include "mini-gmp.h"
|
||||
|
||||
# define GMP_NUMB_MASK (~(mp_limb_t) 0)
|
||||
|
||||
/* Function missing in older gmp versions, and checked for with ifdef */
|
||||
# define mpz_limbs_read mpz_limbs_read
|
||||
/* Side-channel silent powm not available in mini-gmp. */
|
||||
# define mpz_powm_sec mpz_powm
|
||||
#else
|
||||
# include <gmp.h>
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Size needed for signed encoding, including extra sign byte if
|
||||
* necessary. */
|
||||
size_t
|
||||
nettle_mpz_sizeinbase_256_s(const mpz_t x);
|
||||
|
||||
/* Size needed for unsigned encoding */
|
||||
size_t
|
||||
nettle_mpz_sizeinbase_256_u(const mpz_t x);
|
||||
|
||||
/* Writes an integer as length octets, using big endian byte order,
|
||||
* and two's complement for negative numbers. */
|
||||
void
|
||||
nettle_mpz_get_str_256(size_t length, uint8_t *s, const mpz_t x);
|
||||
|
||||
/* Reads a big endian, two's complement, integer. */
|
||||
void
|
||||
nettle_mpz_set_str_256_s(mpz_t x,
|
||||
size_t length, const uint8_t *s);
|
||||
|
||||
void
|
||||
nettle_mpz_init_set_str_256_s(mpz_t x,
|
||||
size_t length, const uint8_t *s);
|
||||
|
||||
/* Similar, but for unsigned format. These function don't interpret
|
||||
* the most significant bit as the sign. */
|
||||
void
|
||||
nettle_mpz_set_str_256_u(mpz_t x,
|
||||
size_t length, const uint8_t *s);
|
||||
|
||||
void
|
||||
nettle_mpz_init_set_str_256_u(mpz_t x,
|
||||
size_t length, const uint8_t *s);
|
||||
|
||||
/* Returns a uniformly distributed random number 0 <= x < 2^n */
|
||||
void
|
||||
nettle_mpz_random_size(mpz_t x,
|
||||
void *ctx, nettle_random_func *random,
|
||||
unsigned bits);
|
||||
|
||||
/* Returns a number x, almost uniformly random in the range
|
||||
* 0 <= x < n. */
|
||||
void
|
||||
nettle_mpz_random(mpz_t x,
|
||||
void *ctx, nettle_random_func *random,
|
||||
const mpz_t n);
|
||||
|
||||
void
|
||||
nettle_random_prime(mpz_t p, unsigned bits, int top_bits_set,
|
||||
void *ctx, nettle_random_func *random,
|
||||
void *progress_ctx, nettle_progress_func *progress);
|
||||
|
||||
void
|
||||
_nettle_generate_pocklington_prime (mpz_t p, mpz_t r,
|
||||
unsigned bits, int top_bits_set,
|
||||
void *ctx, nettle_random_func *random,
|
||||
const mpz_t p0,
|
||||
const mpz_t q,
|
||||
const mpz_t p0q);
|
||||
|
||||
/* sexp parsing */
|
||||
struct sexp_iterator;
|
||||
|
||||
/* If LIMIT is non-zero, the number must be at most LIMIT bits.
|
||||
* Implies sexp_iterator_next. */
|
||||
int
|
||||
nettle_mpz_set_sexp(mpz_t x, unsigned limit, struct sexp_iterator *i);
|
||||
|
||||
|
||||
/* der parsing */
|
||||
struct asn1_der_iterator;
|
||||
|
||||
int
|
||||
nettle_asn1_der_get_bignum(struct asn1_der_iterator *iterator,
|
||||
mpz_t x, unsigned max_bits);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* NETTLE_BIGNUM_H_INCLUDED */
|
||||
@@ -1,89 +0,0 @@
|
||||
/* blowfish.h
|
||||
|
||||
Blowfish block cipher.
|
||||
|
||||
Copyright (C) 2014 Niels Möller
|
||||
Copyright (C) 1998, 2001 FSF, Ray Dassen, Niels Möller
|
||||
|
||||
This file is part of GNU Nettle.
|
||||
|
||||
GNU Nettle is free software: you can redistribute it and/or
|
||||
modify it under the terms of either:
|
||||
|
||||
* the GNU Lesser General Public License as published by the Free
|
||||
Software Foundation; either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or
|
||||
|
||||
* the GNU General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or both in parallel, as here.
|
||||
|
||||
GNU Nettle is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received copies of the GNU General Public License and
|
||||
the GNU Lesser General Public License along with this program. If
|
||||
not, see http://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
#ifndef NETTLE_BLOWFISH_H_INCLUDED
|
||||
#define NETTLE_BLOWFISH_H_INCLUDED
|
||||
|
||||
#include "nettle-types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Name mangling */
|
||||
#define blowfish_set_key nettle_blowfish_set_key
|
||||
#define blowfish128_set_key nettle_blowfish128_set_key
|
||||
#define blowfish_encrypt nettle_blowfish_encrypt
|
||||
#define blowfish_decrypt nettle_blowfish_decrypt
|
||||
|
||||
#define BLOWFISH_BLOCK_SIZE 8
|
||||
|
||||
/* Variable key size between 64 and 448 bits. */
|
||||
#define BLOWFISH_MIN_KEY_SIZE 8
|
||||
#define BLOWFISH_MAX_KEY_SIZE 56
|
||||
|
||||
/* Default to 128 bits */
|
||||
#define BLOWFISH_KEY_SIZE 16
|
||||
|
||||
#define BLOWFISH128_KEY_SIZE 16
|
||||
|
||||
#define _BLOWFISH_ROUNDS 16
|
||||
|
||||
struct blowfish_ctx
|
||||
{
|
||||
uint32_t s[4][256];
|
||||
uint32_t p[_BLOWFISH_ROUNDS+2];
|
||||
};
|
||||
|
||||
/* Returns 0 for weak keys, otherwise 1. */
|
||||
int
|
||||
blowfish_set_key(struct blowfish_ctx *ctx,
|
||||
size_t length, const uint8_t *key);
|
||||
int
|
||||
blowfish128_set_key(struct blowfish_ctx *ctx, const uint8_t *key);
|
||||
|
||||
void
|
||||
blowfish_encrypt(const struct blowfish_ctx *ctx,
|
||||
size_t length, uint8_t *dst,
|
||||
const uint8_t *src);
|
||||
void
|
||||
blowfish_decrypt(const struct blowfish_ctx *ctx,
|
||||
size_t length, uint8_t *dst,
|
||||
const uint8_t *src);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* NETTLE_BLOWFISH_H_INCLUDED */
|
||||
@@ -1,106 +0,0 @@
|
||||
/* buffer.h
|
||||
|
||||
A bare-bones string stream.
|
||||
|
||||
Copyright (C) 2002 Niels Möller
|
||||
|
||||
This file is part of GNU Nettle.
|
||||
|
||||
GNU Nettle is free software: you can redistribute it and/or
|
||||
modify it under the terms of either:
|
||||
|
||||
* the GNU Lesser General Public License as published by the Free
|
||||
Software Foundation; either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or
|
||||
|
||||
* the GNU General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or both in parallel, as here.
|
||||
|
||||
GNU Nettle is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received copies of the GNU General Public License and
|
||||
the GNU Lesser General Public License along with this program. If
|
||||
not, see http://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
#ifndef NETTLE_BUFFER_H_INCLUDED
|
||||
#define NETTLE_BUFFER_H_INCLUDED
|
||||
|
||||
#include "realloc.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct nettle_buffer
|
||||
{
|
||||
uint8_t *contents;
|
||||
/* Allocated size */
|
||||
size_t alloc;
|
||||
|
||||
void *realloc_ctx;
|
||||
nettle_realloc_func *realloc;
|
||||
|
||||
/* Current size */
|
||||
size_t size;
|
||||
};
|
||||
|
||||
/* Initializes a buffer that uses plain realloc */
|
||||
void
|
||||
nettle_buffer_init(struct nettle_buffer *buffer);
|
||||
|
||||
void
|
||||
nettle_buffer_init_realloc(struct nettle_buffer *buffer,
|
||||
void *realloc_ctx,
|
||||
nettle_realloc_func *realloc);
|
||||
|
||||
/* Initializes a buffer of fix size */
|
||||
void
|
||||
nettle_buffer_init_size(struct nettle_buffer *buffer,
|
||||
size_t length, uint8_t *space);
|
||||
|
||||
void
|
||||
nettle_buffer_clear(struct nettle_buffer *buffer);
|
||||
|
||||
/* Resets the buffer, without freeing the buffer space. */
|
||||
void
|
||||
nettle_buffer_reset(struct nettle_buffer *buffer);
|
||||
|
||||
int
|
||||
nettle_buffer_grow(struct nettle_buffer *buffer,
|
||||
size_t length);
|
||||
|
||||
#define NETTLE_BUFFER_PUTC(buffer, c) \
|
||||
( (((buffer)->size < (buffer)->alloc) || nettle_buffer_grow((buffer), 1)) \
|
||||
&& ((buffer)->contents[(buffer)->size++] = (c), 1) )
|
||||
|
||||
int
|
||||
nettle_buffer_write(struct nettle_buffer *buffer,
|
||||
size_t length, const uint8_t *data);
|
||||
|
||||
/* Like nettle_buffer_write, but instead of copying data to the
|
||||
* buffer, it returns a pointer to the area where the caller can copy
|
||||
* the data. The pointer is valid only until the next call that can
|
||||
* reallocate the buffer. */
|
||||
uint8_t *
|
||||
nettle_buffer_space(struct nettle_buffer *buffer,
|
||||
size_t length);
|
||||
|
||||
/* Copy the contents of SRC to the end of DST. */
|
||||
int
|
||||
nettle_buffer_copy(struct nettle_buffer *dst,
|
||||
const struct nettle_buffer *src);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* NETTLE_BUFFER_H_INCLUDED */
|
||||
@@ -1,143 +0,0 @@
|
||||
/* camellia.h
|
||||
|
||||
Copyright (C) 2006,2007 NTT
|
||||
(Nippon Telegraph and Telephone Corporation).
|
||||
|
||||
Copyright (C) 2010, 2013 Niels Möller
|
||||
|
||||
This file is part of GNU Nettle.
|
||||
|
||||
GNU Nettle is free software: you can redistribute it and/or
|
||||
modify it under the terms of either:
|
||||
|
||||
* the GNU Lesser General Public License as published by the Free
|
||||
Software Foundation; either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or
|
||||
|
||||
* the GNU General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or both in parallel, as here.
|
||||
|
||||
GNU Nettle is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received copies of the GNU General Public License and
|
||||
the GNU Lesser General Public License along with this program. If
|
||||
not, see http://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
#ifndef NETTLE_CAMELLIA_H_INCLUDED
|
||||
#define NETTLE_CAMELLIA_H_INCLUDED
|
||||
|
||||
#include "nettle-types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Name mangling */
|
||||
#define camellia128_set_encrypt_key nettle_camellia128_set_encrypt_key
|
||||
#define camellia128_set_decrypt_key nettle_camellia_set_decrypt_key
|
||||
#define camellia128_invert_key nettle_camellia128_invert_key
|
||||
#define camellia128_crypt nettle_camellia128_crypt
|
||||
|
||||
#define camellia192_set_encrypt_key nettle_camellia192_set_encrypt_key
|
||||
#define camellia192_set_decrypt_key nettle_camellia192_set_decrypt_key
|
||||
|
||||
#define camellia256_set_encrypt_key nettle_camellia256_set_encrypt_key
|
||||
#define camellia256_set_decrypt_key nettle_camellia256_set_decrypt_key
|
||||
#define camellia256_invert_key nettle_camellia256_invert_key
|
||||
#define camellia256_crypt nettle_camellia256_crypt
|
||||
|
||||
|
||||
#define CAMELLIA_BLOCK_SIZE 16
|
||||
/* Valid key sizes are 128, 192 or 256 bits (16, 24 or 32 bytes) */
|
||||
#define CAMELLIA128_KEY_SIZE 16
|
||||
#define CAMELLIA192_KEY_SIZE 24
|
||||
#define CAMELLIA256_KEY_SIZE 32
|
||||
|
||||
/* For 128-bit keys, there are 18 regular rounds, pre- and
|
||||
post-whitening, and two FL and FLINV rounds, using a total of 26
|
||||
subkeys, each of 64 bit. For 192- and 256-bit keys, there are 6
|
||||
additional regular rounds and one additional FL and FLINV, using a
|
||||
total of 34 subkeys. */
|
||||
/* The clever combination of subkeys imply one of the pre- and
|
||||
post-whitening keys is folded with the round keys, so that subkey
|
||||
#1 and the last one (#25 or #33) is not used. The result is that we
|
||||
have only 24 or 32 subkeys at the end of key setup. */
|
||||
|
||||
#define _CAMELLIA128_NKEYS 24
|
||||
#define _CAMELLIA256_NKEYS 32
|
||||
|
||||
struct camellia128_ctx
|
||||
{
|
||||
uint64_t keys[_CAMELLIA128_NKEYS];
|
||||
};
|
||||
|
||||
void
|
||||
camellia128_set_encrypt_key(struct camellia128_ctx *ctx,
|
||||
const uint8_t *key);
|
||||
|
||||
void
|
||||
camellia128_set_decrypt_key(struct camellia128_ctx *ctx,
|
||||
const uint8_t *key);
|
||||
|
||||
void
|
||||
camellia128_invert_key(struct camellia128_ctx *dst,
|
||||
const struct camellia128_ctx *src);
|
||||
|
||||
void
|
||||
camellia128_crypt(const struct camellia128_ctx *ctx,
|
||||
size_t length, uint8_t *dst,
|
||||
const uint8_t *src);
|
||||
|
||||
struct camellia256_ctx
|
||||
{
|
||||
uint64_t keys[_CAMELLIA256_NKEYS];
|
||||
};
|
||||
|
||||
void
|
||||
camellia256_set_encrypt_key(struct camellia256_ctx *ctx,
|
||||
const uint8_t *key);
|
||||
|
||||
void
|
||||
camellia256_set_decrypt_key(struct camellia256_ctx *ctx,
|
||||
const uint8_t *key);
|
||||
|
||||
void
|
||||
camellia256_invert_key(struct camellia256_ctx *dst,
|
||||
const struct camellia256_ctx *src);
|
||||
|
||||
void
|
||||
camellia256_crypt(const struct camellia256_ctx *ctx,
|
||||
size_t length, uint8_t *dst,
|
||||
const uint8_t *src);
|
||||
|
||||
/* camellia192 is the same as camellia256, except for the key
|
||||
schedule. */
|
||||
/* Slightly ugly with a #define on a struct tag, since it might cause
|
||||
surprises if also used as a name of a variable. */
|
||||
#define camellia192_ctx camellia256_ctx
|
||||
|
||||
void
|
||||
camellia192_set_encrypt_key(struct camellia256_ctx *ctx,
|
||||
const uint8_t *key);
|
||||
|
||||
void
|
||||
camellia192_set_decrypt_key(struct camellia256_ctx *ctx,
|
||||
const uint8_t *key);
|
||||
|
||||
#define camellia192_invert_key camellia256_invert_key
|
||||
#define camellia192_crypt camellia256_crypt
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* NETTLE_CAMELLIA_H_INCLUDED */
|
||||
@@ -1,86 +0,0 @@
|
||||
/* cast128.h
|
||||
|
||||
The CAST-128 block cipher.
|
||||
|
||||
Copyright (C) 2001, 2014 Niels Möller
|
||||
|
||||
This file is part of GNU Nettle.
|
||||
|
||||
GNU Nettle is free software: you can redistribute it and/or
|
||||
modify it under the terms of either:
|
||||
|
||||
* the GNU Lesser General Public License as published by the Free
|
||||
Software Foundation; either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or
|
||||
|
||||
* the GNU General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or both in parallel, as here.
|
||||
|
||||
GNU Nettle is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received copies of the GNU General Public License and
|
||||
the GNU Lesser General Public License along with this program. If
|
||||
not, see http://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
#ifndef NETTLE_CAST128_H_INCLUDED
|
||||
#define NETTLE_CAST128_H_INCLUDED
|
||||
|
||||
#include "nettle-types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Name mangling */
|
||||
#define cast5_set_key nettle_cast5_set_key
|
||||
#define cast128_set_key nettle_cast128_set_key
|
||||
#define cast128_encrypt nettle_cast128_encrypt
|
||||
#define cast128_decrypt nettle_cast128_decrypt
|
||||
|
||||
#define CAST128_BLOCK_SIZE 8
|
||||
|
||||
/* Variable key size between 40 and 128. */
|
||||
#define CAST5_MIN_KEY_SIZE 5
|
||||
#define CAST5_MAX_KEY_SIZE 16
|
||||
|
||||
#define CAST128_KEY_SIZE 16
|
||||
|
||||
struct cast128_ctx
|
||||
{
|
||||
unsigned rounds; /* Number of rounds to use, 12 or 16 */
|
||||
/* Expanded key, rotations (5 bits only) and 32-bit masks. */
|
||||
unsigned char Kr[16];
|
||||
uint32_t Km[16];
|
||||
};
|
||||
|
||||
/* Using variable key size. */
|
||||
void
|
||||
cast5_set_key(struct cast128_ctx *ctx,
|
||||
size_t length, const uint8_t *key);
|
||||
|
||||
void
|
||||
cast128_set_key(struct cast128_ctx *ctx, const uint8_t *key);
|
||||
|
||||
void
|
||||
cast128_encrypt(const struct cast128_ctx *ctx,
|
||||
size_t length, uint8_t *dst,
|
||||
const uint8_t *src);
|
||||
void
|
||||
cast128_decrypt(const struct cast128_ctx *ctx,
|
||||
size_t length, uint8_t *dst,
|
||||
const uint8_t *src);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* NETTLE_CAST128_H_INCLUDED */
|
||||
@@ -1,86 +0,0 @@
|
||||
/* cbc.h
|
||||
|
||||
Cipher block chaining mode.
|
||||
|
||||
Copyright (C) 2001 Niels Möller
|
||||
|
||||
This file is part of GNU Nettle.
|
||||
|
||||
GNU Nettle is free software: you can redistribute it and/or
|
||||
modify it under the terms of either:
|
||||
|
||||
* the GNU Lesser General Public License as published by the Free
|
||||
Software Foundation; either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or
|
||||
|
||||
* the GNU General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or both in parallel, as here.
|
||||
|
||||
GNU Nettle is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received copies of the GNU General Public License and
|
||||
the GNU Lesser General Public License along with this program. If
|
||||
not, see http://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
#ifndef NETTLE_CBC_H_INCLUDED
|
||||
#define NETTLE_CBC_H_INCLUDED
|
||||
|
||||
#include "nettle-types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Name mangling */
|
||||
#define cbc_encrypt nettle_cbc_encrypt
|
||||
#define cbc_decrypt nettle_cbc_decrypt
|
||||
|
||||
void
|
||||
cbc_encrypt(const void *ctx, nettle_cipher_func *f,
|
||||
size_t block_size, uint8_t *iv,
|
||||
size_t length, uint8_t *dst,
|
||||
const uint8_t *src);
|
||||
|
||||
void
|
||||
cbc_decrypt(const void *ctx, nettle_cipher_func *f,
|
||||
size_t block_size, uint8_t *iv,
|
||||
size_t length, uint8_t *dst,
|
||||
const uint8_t *src);
|
||||
|
||||
#define CBC_CTX(type, size) \
|
||||
{ type ctx; uint8_t iv[size]; }
|
||||
|
||||
#define CBC_SET_IV(ctx, data) \
|
||||
memcpy((ctx)->iv, (data), sizeof((ctx)->iv))
|
||||
|
||||
/* NOTE: Avoid using NULL, as we don't include anything defining it. */
|
||||
#define CBC_ENCRYPT(self, f, length, dst, src) \
|
||||
(0 ? ((f)(&(self)->ctx, ~(size_t) 0, \
|
||||
(uint8_t *) 0, (const uint8_t *) 0)) \
|
||||
: cbc_encrypt((void *) &(self)->ctx, \
|
||||
(nettle_cipher_func *) (f), \
|
||||
sizeof((self)->iv), (self)->iv, \
|
||||
(length), (dst), (src)))
|
||||
|
||||
#define CBC_DECRYPT(self, f, length, dst, src) \
|
||||
(0 ? ((f)(&(self)->ctx, ~(size_t) 0, \
|
||||
(uint8_t *) 0, (const uint8_t *) 0)) \
|
||||
: cbc_decrypt((void *) &(self)->ctx, \
|
||||
(nettle_cipher_func *) (f), \
|
||||
sizeof((self)->iv), (self)->iv, \
|
||||
(length), (dst), (src)))
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* NETTLE_CBC_H_INCLUDED */
|
||||
@@ -1,302 +0,0 @@
|
||||
/* ccm.h
|
||||
|
||||
Counter with CBC-MAC mode, specified by NIST,
|
||||
http://csrc.nist.gov/publications/nistpubs/800-38C/SP800-38C_updated-July20_2007.pdf
|
||||
|
||||
Copyright (C) 2014 Exegin Technologies Limited
|
||||
Copyright (C) 2014 Owen Kirby
|
||||
|
||||
Contributed to GNU Nettle by Owen Kirby
|
||||
|
||||
This file is part of GNU Nettle.
|
||||
|
||||
GNU Nettle is free software: you can redistribute it and/or
|
||||
modify it under the terms of either:
|
||||
|
||||
* the GNU Lesser General Public License as published by the Free
|
||||
Software Foundation; either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or
|
||||
|
||||
* the GNU General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or both in parallel, as here.
|
||||
|
||||
GNU Nettle is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received copies of the GNU General Public License and
|
||||
the GNU Lesser General Public License along with this program. If
|
||||
not, see http://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
/* NIST SP800-38C doesn't specify the particular formatting and
|
||||
* counter generation algorithm for CCM, but it does include an
|
||||
* example algorithm. This example has become the de-factor standard,
|
||||
* and has been adopted by both the IETF and IEEE across a wide
|
||||
* variety of protocols.
|
||||
*/
|
||||
|
||||
#ifndef NETTLE_CCM_H_INCLUDED
|
||||
#define NETTLE_CCM_H_INCLUDED
|
||||
|
||||
#include "aes.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Name mangling */
|
||||
#define ccm_set_nonce nettle_ccm_set_nonce
|
||||
#define ccm_update nettle_ccm_update
|
||||
#define ccm_encrypt nettle_ccm_encrypt
|
||||
#define ccm_decrypt nettle_ccm_decrypt
|
||||
#define ccm_digest nettle_ccm_digest
|
||||
#define ccm_encrypt_message nettle_ccm_encrypt_message
|
||||
#define ccm_decrypt_message nettle_ccm_decrypt_message
|
||||
|
||||
#define ccm_aes128_set_key nettle_ccm_aes128_set_key
|
||||
#define ccm_aes128_set_nonce nettle_ccm_aes128_set_nonce
|
||||
#define ccm_aes128_update nettle_ccm_aes128_update
|
||||
#define ccm_aes128_encrypt nettle_ccm_aes128_encrypt
|
||||
#define ccm_aes128_decrypt nettle_ccm_aes128_decrypt
|
||||
#define ccm_aes128_digest nettle_ccm_aes128_digest
|
||||
#define ccm_aes128_encrypt_message nettle_ccm_aes128_encrypt_message
|
||||
#define ccm_aes128_decrypt_message nettle_ccm_aes128_decrypt_message
|
||||
|
||||
#define ccm_aes192_set_key nettle_ccm_aes192_set_key
|
||||
#define ccm_aes192_set_nonce nettle_ccm_aes192_set_nonce
|
||||
#define ccm_aes192_update nettle_ccm_aes192_update
|
||||
#define ccm_aes192_encrypt nettle_ccm_aes192_encrypt
|
||||
#define ccm_aes192_decrypt nettle_ccm_aes192_decrypt
|
||||
#define ccm_aes192_digest nettle_ccm_aes192_digest
|
||||
#define ccm_aes192_encrypt_message nettle_ccm_aes192_encrypt_message
|
||||
#define ccm_aes192_decrypt_message nettle_ccm_aes192_decrypt_message
|
||||
|
||||
#define ccm_aes256_set_key nettle_ccm_aes256_set_key
|
||||
#define ccm_aes256_set_nonce nettle_ccm_aes256_set_nonce
|
||||
#define ccm_aes256_update nettle_ccm_aes256_update
|
||||
#define ccm_aes256_encrypt nettle_ccm_aes256_encrypt
|
||||
#define ccm_aes256_decrypt nettle_ccm_aes256_decrypt
|
||||
#define ccm_aes256_digest nettle_ccm_aes256_digest
|
||||
#define ccm_aes256_encrypt_message nettle_ccm_aes256_encrypt_message
|
||||
#define ccm_aes256_decrypt_message nettle_ccm_aes256_decrypt_message
|
||||
|
||||
/* For CCM, the block size of the block cipher shall be 128 bits. */
|
||||
#define CCM_BLOCK_SIZE 16
|
||||
#define CCM_DIGEST_SIZE 16
|
||||
#define CCM_MIN_NONCE_SIZE 7
|
||||
#define CCM_MAX_NONCE_SIZE 14
|
||||
|
||||
/* Maximum cleartext message size, as a function of the nonce size N.
|
||||
The length field is L octets, with L = 15 - N, and then the maximum
|
||||
size M = 2^{8L} - 1. */
|
||||
#define CCM_MAX_MSG_SIZE(N) \
|
||||
((sizeof(size_t) + (N) <= 15) \
|
||||
? ~(size_t) 0 \
|
||||
: ((size_t) 1 << (8*(15 - N))) - 1)
|
||||
|
||||
/* Per-message state */
|
||||
struct ccm_ctx {
|
||||
union nettle_block16 ctr; /* Counter for CTR encryption. */
|
||||
union nettle_block16 tag; /* CBC-MAC message tag. */
|
||||
/* Length of data processed by the CBC-MAC modulus the block size */
|
||||
unsigned int blength;
|
||||
};
|
||||
|
||||
/*
|
||||
* CCM mode requires the adata and message lengths when building the IV, which
|
||||
* prevents streaming processing and it incompatible with the AEAD API.
|
||||
*/
|
||||
void
|
||||
ccm_set_nonce(struct ccm_ctx *ctx, const void *cipher, nettle_cipher_func *f,
|
||||
size_t noncelen, const uint8_t *nonce,
|
||||
size_t authlen, size_t msglen, size_t taglen);
|
||||
|
||||
void
|
||||
ccm_update(struct ccm_ctx *ctx, const void *cipher, nettle_cipher_func *f,
|
||||
size_t length, const uint8_t *data);
|
||||
|
||||
void
|
||||
ccm_encrypt(struct ccm_ctx *ctx, const void *cipher, nettle_cipher_func *f,
|
||||
size_t length, uint8_t *dst, const uint8_t *src);
|
||||
|
||||
void
|
||||
ccm_decrypt(struct ccm_ctx *ctx, const void *cipher, nettle_cipher_func *f,
|
||||
size_t length, uint8_t *dst, const uint8_t *src);
|
||||
|
||||
void
|
||||
ccm_digest(struct ccm_ctx *ctx, const void *cipher, nettle_cipher_func *f,
|
||||
size_t length, uint8_t *digest);
|
||||
|
||||
/*
|
||||
* All-in-one encryption and decryption API:
|
||||
* tlength = sizeof(digest)
|
||||
* mlength = sizeof(cleartext)
|
||||
* clength = sizeof(ciphertext) = mlength + tlength
|
||||
*
|
||||
* The ciphertext will contain the encrypted payload with the message digest
|
||||
* appended to the end.
|
||||
*/
|
||||
void
|
||||
ccm_encrypt_message(const void *cipher, nettle_cipher_func *f,
|
||||
size_t nlength, const uint8_t *nonce,
|
||||
size_t alength, const uint8_t *adata,
|
||||
size_t tlength,
|
||||
size_t clength, uint8_t *dst, const uint8_t *src);
|
||||
|
||||
/*
|
||||
* The decryption function will write the plaintext to dst and parse the digest
|
||||
* from the final tlength bytes of the ciphertext. If the digest matched the
|
||||
* value computed during decryption then this will return 1, or it will return
|
||||
* 0 if the digest was invalid.
|
||||
*/
|
||||
int
|
||||
ccm_decrypt_message(const void *cipher, nettle_cipher_func *f,
|
||||
size_t nlength, const uint8_t *nonce,
|
||||
size_t alength, const uint8_t *adata,
|
||||
size_t tlength,
|
||||
size_t mlength, uint8_t *dst, const uint8_t *src);
|
||||
|
||||
/* CCM Mode with AES-128 */
|
||||
struct ccm_aes128_ctx {
|
||||
struct ccm_ctx ccm;
|
||||
struct aes128_ctx cipher;
|
||||
};
|
||||
|
||||
void
|
||||
ccm_aes128_set_key(struct ccm_aes128_ctx *ctx, const uint8_t *key);
|
||||
|
||||
void
|
||||
ccm_aes128_set_nonce(struct ccm_aes128_ctx *ctx,
|
||||
size_t length, const uint8_t *nonce,
|
||||
size_t authlen, size_t msglen, size_t taglen);
|
||||
|
||||
void
|
||||
ccm_aes128_update (struct ccm_aes128_ctx *ctx,
|
||||
size_t length, const uint8_t *data);
|
||||
|
||||
void
|
||||
ccm_aes128_encrypt(struct ccm_aes128_ctx *ctx,
|
||||
size_t length, uint8_t *dst, const uint8_t *src);
|
||||
|
||||
void
|
||||
ccm_aes128_decrypt(struct ccm_aes128_ctx *ctx,
|
||||
size_t length, uint8_t *dst, const uint8_t *src);
|
||||
|
||||
void
|
||||
ccm_aes128_digest(struct ccm_aes128_ctx *ctx,
|
||||
size_t length, uint8_t *digest);
|
||||
|
||||
void
|
||||
ccm_aes128_encrypt_message(struct ccm_aes128_ctx *ctx,
|
||||
size_t nlength, const uint8_t *nonce,
|
||||
size_t alength, const uint8_t *adata,
|
||||
size_t tlength,
|
||||
size_t clength, uint8_t *dst, const uint8_t *src);
|
||||
|
||||
int
|
||||
ccm_aes128_decrypt_message(struct ccm_aes128_ctx *ctx,
|
||||
size_t nlength, const uint8_t *nonce,
|
||||
size_t alength, const uint8_t *adata,
|
||||
size_t tlength,
|
||||
size_t mlength, uint8_t *dst, const uint8_t *src);
|
||||
|
||||
struct ccm_aes192_ctx {
|
||||
struct ccm_ctx ccm;
|
||||
struct aes192_ctx cipher;
|
||||
};
|
||||
|
||||
/* CCM Mode with AES-192 */
|
||||
void
|
||||
ccm_aes192_set_key(struct ccm_aes192_ctx *ctx, const uint8_t *key);
|
||||
|
||||
void
|
||||
ccm_aes192_set_nonce(struct ccm_aes192_ctx *ctx,
|
||||
size_t length, const uint8_t *nonce,
|
||||
size_t authlen, size_t msglen, size_t taglen);
|
||||
|
||||
void
|
||||
ccm_aes192_update(struct ccm_aes192_ctx *ctx,
|
||||
size_t length, const uint8_t *data);
|
||||
|
||||
void
|
||||
ccm_aes192_encrypt(struct ccm_aes192_ctx *ctx,
|
||||
size_t length, uint8_t *dst, const uint8_t *src);
|
||||
|
||||
void
|
||||
ccm_aes192_decrypt(struct ccm_aes192_ctx *ctx,
|
||||
size_t length, uint8_t *dst, const uint8_t *src);
|
||||
|
||||
void
|
||||
ccm_aes192_digest(struct ccm_aes192_ctx *ctx,
|
||||
size_t length, uint8_t *digest);
|
||||
|
||||
void
|
||||
ccm_aes192_encrypt_message(struct ccm_aes192_ctx *ctx,
|
||||
size_t nlength, const uint8_t *nonce,
|
||||
size_t alength, const uint8_t *adata,
|
||||
size_t tlength,
|
||||
size_t clength, uint8_t *dst, const uint8_t *src);
|
||||
|
||||
int
|
||||
ccm_aes192_decrypt_message(struct ccm_aes192_ctx *ctx,
|
||||
size_t nlength, const uint8_t *nonce,
|
||||
size_t alength, const uint8_t *adata,
|
||||
size_t tlength,
|
||||
size_t mlength, uint8_t *dst, const uint8_t *src);
|
||||
|
||||
/* CCM Mode with AES-256 */
|
||||
struct ccm_aes256_ctx {
|
||||
struct ccm_ctx ccm;
|
||||
struct aes256_ctx cipher;
|
||||
};
|
||||
|
||||
void
|
||||
ccm_aes256_set_key(struct ccm_aes256_ctx *ctx, const uint8_t *key);
|
||||
|
||||
void
|
||||
ccm_aes256_set_nonce(struct ccm_aes256_ctx *ctx,
|
||||
size_t length, const uint8_t *nonce,
|
||||
size_t authlen, size_t msglen, size_t taglen);
|
||||
|
||||
void
|
||||
ccm_aes256_update(struct ccm_aes256_ctx *ctx,
|
||||
size_t length, const uint8_t *data);
|
||||
|
||||
void
|
||||
ccm_aes256_encrypt(struct ccm_aes256_ctx *ctx,
|
||||
size_t length, uint8_t *dst, const uint8_t *src);
|
||||
|
||||
void
|
||||
ccm_aes256_decrypt(struct ccm_aes256_ctx *ctx,
|
||||
size_t length, uint8_t *dst, const uint8_t *src);
|
||||
|
||||
void
|
||||
ccm_aes256_digest(struct ccm_aes256_ctx *ctx,
|
||||
size_t length, uint8_t *digest);
|
||||
|
||||
void
|
||||
ccm_aes256_encrypt_message(struct ccm_aes256_ctx *ctx,
|
||||
size_t nlength, const uint8_t *nonce,
|
||||
size_t alength, const uint8_t *adata,
|
||||
size_t tlength,
|
||||
size_t clength, uint8_t *dst, const uint8_t *src);
|
||||
|
||||
int
|
||||
ccm_aes256_decrypt_message(struct ccm_aes256_ctx *ctx,
|
||||
size_t nlength, const uint8_t *nonce,
|
||||
size_t alength, const uint8_t *adata,
|
||||
size_t tlength,
|
||||
size_t mlength, uint8_t *dst, const uint8_t *src);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* NETTLE_CCM_H_INCLUDED */
|
||||
@@ -1,87 +0,0 @@
|
||||
/* cfb.h
|
||||
|
||||
Cipher feedback mode.
|
||||
|
||||
Copyright (C) 2015, 2017 Dmitry Eremin-Solenikov
|
||||
Copyright (C) 2001 Niels Möller
|
||||
|
||||
This file is part of GNU Nettle.
|
||||
|
||||
GNU Nettle is free software: you can redistribute it and/or
|
||||
modify it under the terms of either:
|
||||
|
||||
* the GNU Lesser General Public License as published by the Free
|
||||
Software Foundation; either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or
|
||||
|
||||
* the GNU General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or both in parallel, as here.
|
||||
|
||||
GNU Nettle is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received copies of the GNU General Public License and
|
||||
the GNU Lesser General Public License along with this program. If
|
||||
not, see http://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
#ifndef NETTLE_CFB_H_INCLUDED
|
||||
#define NETTLE_CFB_H_INCLUDED
|
||||
|
||||
#include "nettle-types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Name mangling */
|
||||
#define cfb_encrypt nettle_cfb_encrypt
|
||||
#define cfb_decrypt nettle_cfb_decrypt
|
||||
|
||||
void
|
||||
cfb_encrypt(const void *ctx, nettle_cipher_func *f,
|
||||
size_t block_size, uint8_t *iv,
|
||||
size_t length, uint8_t *dst,
|
||||
const uint8_t *src);
|
||||
|
||||
void
|
||||
cfb_decrypt(const void *ctx, nettle_cipher_func *f,
|
||||
size_t block_size, uint8_t *iv,
|
||||
size_t length, uint8_t *dst,
|
||||
const uint8_t *src);
|
||||
|
||||
#define CFB_CTX(type, size) \
|
||||
{ type ctx; uint8_t iv[size]; }
|
||||
|
||||
#define CFB_SET_IV(ctx, data) \
|
||||
memcpy((ctx)->iv, (data), sizeof((ctx)->iv))
|
||||
|
||||
/* NOTE: Avoid using NULL, as we don't include anything defining it. */
|
||||
#define CFB_ENCRYPT(self, f, length, dst, src) \
|
||||
(0 ? ((f)(&(self)->ctx, ~(size_t) 0, \
|
||||
(uint8_t *) 0, (const uint8_t *) 0)) \
|
||||
: cfb_encrypt((void *) &(self)->ctx, \
|
||||
(nettle_cipher_func *) (f), \
|
||||
sizeof((self)->iv), (self)->iv, \
|
||||
(length), (dst), (src)))
|
||||
|
||||
#define CFB_DECRYPT(self, f, length, dst, src) \
|
||||
(0 ? ((f)(&(self)->ctx, ~(size_t) 0, \
|
||||
(uint8_t *) 0, (const uint8_t *) 0)) \
|
||||
: cfb_decrypt((void *) &(self)->ctx, \
|
||||
(nettle_cipher_func *) (f), \
|
||||
sizeof((self)->iv), (self)->iv, \
|
||||
(length), (dst), (src)))
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* NETTLE_CFB_H_INCLUDED */
|
||||
@@ -1,98 +0,0 @@
|
||||
/* chacha-poly1305.h
|
||||
|
||||
AEAD mechanism based on chacha and poly1305.
|
||||
See draft-agl-tls-chacha20poly1305-04.
|
||||
|
||||
Copyright (C) 2014 Niels Möller
|
||||
|
||||
This file is part of GNU Nettle.
|
||||
|
||||
GNU Nettle is free software: you can redistribute it and/or
|
||||
modify it under the terms of either:
|
||||
|
||||
* the GNU Lesser General Public License as published by the Free
|
||||
Software Foundation; either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or
|
||||
|
||||
* the GNU General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or both in parallel, as here.
|
||||
|
||||
GNU Nettle is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received copies of the GNU General Public License and
|
||||
the GNU Lesser General Public License along with this program. If
|
||||
not, see http://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
#ifndef NETTLE_CHACHA_POLY1305_H_INCLUDED
|
||||
#define NETTLE_CHACHA_POLY1305_H_INCLUDED
|
||||
|
||||
#include "chacha.h"
|
||||
#include "poly1305.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Name mangling */
|
||||
#define chacha_poly1305_set_key nettle_chacha_poly1305_set_key
|
||||
#define chacha_poly1305_set_nonce nettle_chacha_poly1305_set_nonce
|
||||
#define chacha_poly1305_update nettle_chacha_poly1305_update
|
||||
#define chacha_poly1305_decrypt nettle_chacha_poly1305_decrypt
|
||||
#define chacha_poly1305_encrypt nettle_chacha_poly1305_encrypt
|
||||
#define chacha_poly1305_digest nettle_chacha_poly1305_digest
|
||||
|
||||
#define CHACHA_POLY1305_BLOCK_SIZE 64
|
||||
/* FIXME: Any need for 128-bit variant? */
|
||||
#define CHACHA_POLY1305_KEY_SIZE 32
|
||||
#define CHACHA_POLY1305_NONCE_SIZE CHACHA_NONCE96_SIZE
|
||||
#define CHACHA_POLY1305_DIGEST_SIZE 16
|
||||
|
||||
struct chacha_poly1305_ctx
|
||||
{
|
||||
struct chacha_ctx chacha;
|
||||
struct poly1305_ctx poly1305;
|
||||
union nettle_block16 s;
|
||||
uint64_t auth_size;
|
||||
uint64_t data_size;
|
||||
/* poly1305 block */
|
||||
uint8_t block[POLY1305_BLOCK_SIZE];
|
||||
unsigned index;
|
||||
};
|
||||
|
||||
void
|
||||
chacha_poly1305_set_key (struct chacha_poly1305_ctx *ctx,
|
||||
const uint8_t *key);
|
||||
void
|
||||
chacha_poly1305_set_nonce (struct chacha_poly1305_ctx *ctx,
|
||||
const uint8_t *nonce);
|
||||
|
||||
void
|
||||
chacha_poly1305_update (struct chacha_poly1305_ctx *ctx,
|
||||
size_t length, const uint8_t *data);
|
||||
|
||||
void
|
||||
chacha_poly1305_encrypt (struct chacha_poly1305_ctx *ctx,
|
||||
size_t length, uint8_t *dst, const uint8_t *src);
|
||||
|
||||
void
|
||||
chacha_poly1305_decrypt (struct chacha_poly1305_ctx *ctx,
|
||||
size_t length, uint8_t *dst, const uint8_t *src);
|
||||
|
||||
void
|
||||
chacha_poly1305_digest (struct chacha_poly1305_ctx *ctx,
|
||||
size_t length, uint8_t *digest);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* NETTLE_CHACHA_POLY1305_H_INCLUDED */
|
||||
@@ -1,96 +0,0 @@
|
||||
/* chacha.h
|
||||
|
||||
The ChaCha stream cipher.
|
||||
|
||||
Copyright (C) 2013 Joachim Strömbergson
|
||||
Copyright (C) 2012 Simon Josefsson
|
||||
Copyright (C) 2014 Niels Möller
|
||||
|
||||
This file is part of GNU Nettle.
|
||||
|
||||
GNU Nettle is free software: you can redistribute it and/or
|
||||
modify it under the terms of either:
|
||||
|
||||
* the GNU Lesser General Public License as published by the Free
|
||||
Software Foundation; either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or
|
||||
|
||||
* the GNU General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or both in parallel, as here.
|
||||
|
||||
GNU Nettle is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received copies of the GNU General Public License and
|
||||
the GNU Lesser General Public License along with this program. If
|
||||
not, see http://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
#ifndef NETTLE_CHACHA_H_INCLUDED
|
||||
#define NETTLE_CHACHA_H_INCLUDED
|
||||
|
||||
#include "nettle-types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Name mangling */
|
||||
#define chacha_set_key nettle_chacha_set_key
|
||||
#define chacha_set_nonce nettle_chacha_set_nonce
|
||||
#define chacha_set_nonce96 nettle_chacha_set_nonce96
|
||||
#define chacha_crypt nettle_chacha_crypt
|
||||
#define _chacha_core _nettle_chacha_core
|
||||
|
||||
/* Currently, only 256-bit keys are supported. */
|
||||
#define CHACHA_KEY_SIZE 32
|
||||
#define CHACHA_BLOCK_SIZE 64
|
||||
#define CHACHA_NONCE_SIZE 8
|
||||
#define CHACHA_NONCE96_SIZE 12
|
||||
|
||||
#define _CHACHA_STATE_LENGTH 16
|
||||
|
||||
struct chacha_ctx
|
||||
{
|
||||
/* Indices 0-3 holds a constant (SIGMA or TAU).
|
||||
Indices 4-11 holds the key.
|
||||
Indices 12-13 holds the block counter.
|
||||
Indices 14-15 holds the IV:
|
||||
|
||||
This creates the state matrix:
|
||||
C C C C
|
||||
K K K K
|
||||
K K K K
|
||||
B B I I
|
||||
*/
|
||||
uint32_t state[_CHACHA_STATE_LENGTH];
|
||||
};
|
||||
|
||||
void
|
||||
chacha_set_key(struct chacha_ctx *ctx, const uint8_t *key);
|
||||
|
||||
void
|
||||
chacha_set_nonce(struct chacha_ctx *ctx, const uint8_t *nonce);
|
||||
|
||||
void
|
||||
chacha_set_nonce96(struct chacha_ctx *ctx, const uint8_t *nonce);
|
||||
|
||||
void
|
||||
chacha_crypt(struct chacha_ctx *ctx, size_t length,
|
||||
uint8_t *dst, const uint8_t *src);
|
||||
|
||||
void
|
||||
_chacha_core(uint32_t *dst, const uint32_t *src, unsigned rounds);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* NETTLE_CHACHA_H_INCLUDED */
|
||||
@@ -1,71 +0,0 @@
|
||||
/* ctr.h
|
||||
|
||||
Counter mode, using an network byte order incremented counter,
|
||||
matching the testcases of NIST 800-38A.
|
||||
|
||||
Copyright (C) 2005 Niels Möller
|
||||
|
||||
This file is part of GNU Nettle.
|
||||
|
||||
GNU Nettle is free software: you can redistribute it and/or
|
||||
modify it under the terms of either:
|
||||
|
||||
* the GNU Lesser General Public License as published by the Free
|
||||
Software Foundation; either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or
|
||||
|
||||
* the GNU General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or both in parallel, as here.
|
||||
|
||||
GNU Nettle is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received copies of the GNU General Public License and
|
||||
the GNU Lesser General Public License along with this program. If
|
||||
not, see http://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
#ifndef NETTLE_CTR_H_INCLUDED
|
||||
#define NETTLE_CTR_H_INCLUDED
|
||||
|
||||
#include "nettle-types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Name mangling */
|
||||
#define ctr_crypt nettle_ctr_crypt
|
||||
|
||||
void
|
||||
ctr_crypt(const void *ctx, nettle_cipher_func *f,
|
||||
size_t block_size, uint8_t *ctr,
|
||||
size_t length, uint8_t *dst,
|
||||
const uint8_t *src);
|
||||
|
||||
#define CTR_CTX(type, size) \
|
||||
{ type ctx; uint8_t ctr[size]; }
|
||||
|
||||
#define CTR_SET_COUNTER(ctx, data) \
|
||||
memcpy((ctx)->ctr, (data), sizeof((ctx)->ctr))
|
||||
|
||||
#define CTR_CRYPT(self, f, length, dst, src) \
|
||||
(0 ? ((f)(&(self)->ctx, ~(size_t) 0, \
|
||||
(uint8_t *) 0, (const uint8_t *) 0)) \
|
||||
: ctr_crypt((void *) &(self)->ctx, \
|
||||
(nettle_cipher_func *) (f), \
|
||||
sizeof((self)->ctr), (self)->ctr, \
|
||||
(length), (dst), (src)))
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* NETTLE_CTR_H_INCLUDED */
|
||||
@@ -1,60 +0,0 @@
|
||||
/* curve25519.h
|
||||
|
||||
Copyright (C) 2014 Niels Möller
|
||||
|
||||
This file is part of GNU Nettle.
|
||||
|
||||
GNU Nettle is free software: you can redistribute it and/or
|
||||
modify it under the terms of either:
|
||||
|
||||
* the GNU Lesser General Public License as published by the Free
|
||||
Software Foundation; either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or
|
||||
|
||||
* the GNU General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or both in parallel, as here.
|
||||
|
||||
GNU Nettle is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received copies of the GNU General Public License and
|
||||
the GNU Lesser General Public License along with this program. If
|
||||
not, see http://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
#ifndef NETTLE_CURVE25519_H
|
||||
#define NETTLE_CURVE25519_H
|
||||
|
||||
#include "nettle-types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Name mangling */
|
||||
#define curve25519_mul_g nettle_curve25519_mul_g
|
||||
#define curve25519_mul nettle_curve25519_mul
|
||||
|
||||
#define CURVE25519_SIZE 32
|
||||
|
||||
/* Indicates that curve25519_mul conforms to RFC 7748. */
|
||||
#define NETTLE_CURVE25519_RFC7748 1
|
||||
|
||||
void
|
||||
curve25519_mul_g (uint8_t *q, const uint8_t *n);
|
||||
|
||||
void
|
||||
curve25519_mul (uint8_t *q, const uint8_t *n, const uint8_t *p);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* NETTLE_CURVE25519_H */
|
||||
@@ -1,162 +0,0 @@
|
||||
/* des-compat.h
|
||||
|
||||
The des block cipher, old libdes/openssl-style interface.
|
||||
|
||||
Copyright (C) 2001 Niels Möller
|
||||
|
||||
This file is part of GNU Nettle.
|
||||
|
||||
GNU Nettle is free software: you can redistribute it and/or
|
||||
modify it under the terms of either:
|
||||
|
||||
* the GNU Lesser General Public License as published by the Free
|
||||
Software Foundation; either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or
|
||||
|
||||
* the GNU General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or both in parallel, as here.
|
||||
|
||||
GNU Nettle is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received copies of the GNU General Public License and
|
||||
the GNU Lesser General Public License along with this program. If
|
||||
not, see http://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
#ifndef NETTLE_DES_COMPAT_H_INCLUDED
|
||||
#define NETTLE_DES_COMPAT_H_INCLUDED
|
||||
|
||||
/* According to Assar, des_set_key, des_set_key_odd_parity,
|
||||
* des_is_weak_key, plus the encryption functions (des_*_encrypt and
|
||||
* des_cbc_cksum) would be a pretty useful subset. */
|
||||
|
||||
/* NOTE: This is quite experimental, and not all functions are
|
||||
* implemented. Contributions, in particular test cases are welcome. */
|
||||
|
||||
#include "des.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* We use some name mangling, to avoid collisions with either other
|
||||
* nettle functions or with libcrypto. */
|
||||
|
||||
#define des_ecb3_encrypt nettle_openssl_des_ecb3_encrypt
|
||||
#define des_cbc_cksum nettle_openssl_des_cbc_cksum
|
||||
#define des_ncbc_encrypt nettle_openssl_des_ncbc_encrypt
|
||||
#define des_cbc_encrypt nettle_openssl_des_cbc_encrypt
|
||||
#define des_ecb_encrypt nettle_openssl_des_ecb_encrypt
|
||||
#define des_ede3_cbc_encrypt nettle_openssl_des_ede3_cbc_encrypt
|
||||
#define des_set_odd_parity nettle_openssl_des_set_odd_parity
|
||||
#define des_check_key nettle_openssl_des_check_key
|
||||
#define des_key_sched nettle_openssl_des_key_sched
|
||||
#define des_is_weak_key nettle_openssl_des_is_weak_key
|
||||
|
||||
/* An extra alias */
|
||||
#undef des_set_key
|
||||
#define des_set_key nettle_openssl_des_key_sched
|
||||
|
||||
enum { DES_DECRYPT = 0, DES_ENCRYPT = 1 };
|
||||
|
||||
/* Types */
|
||||
typedef uint32_t DES_LONG;
|
||||
|
||||
/* Note: Typedef:ed arrays should be avoided, but they're used here
|
||||
* for compatibility. */
|
||||
typedef struct des_ctx des_key_schedule[1];
|
||||
|
||||
typedef uint8_t des_cblock[DES_BLOCK_SIZE];
|
||||
/* Note: The proper definition,
|
||||
|
||||
typedef const uint8_t const_des_cblock[DES_BLOCK_SIZE];
|
||||
|
||||
would have worked, *if* all the prototypes had used arguments like
|
||||
foo(const_des_cblock src, des_cblock dst), letting argument arrays
|
||||
"decay" into pointers of type uint8_t * and const uint8_t *.
|
||||
|
||||
But since openssl's prototypes use *pointers* const_des_cblock *src,
|
||||
des_cblock *dst, this ends up in type conflicts, and the workaround
|
||||
is to not use const at all.
|
||||
*/
|
||||
#define const_des_cblock des_cblock
|
||||
|
||||
/* Aliases */
|
||||
#define des_ecb2_encrypt(i,o,k1,k2,e) \
|
||||
des_ecb3_encrypt((i),(o),(k1),(k2),(k1),(e))
|
||||
|
||||
#define des_ede2_cbc_encrypt(i,o,l,k1,k2,iv,e) \
|
||||
des_ede3_cbc_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(e))
|
||||
|
||||
/* Global flag */
|
||||
extern int des_check_key;
|
||||
|
||||
/* Prototypes */
|
||||
|
||||
/* Typing is a little confusing. Since both des_cblock and
|
||||
des_key_schedule are typedef:ed arrays, it automatically decay to
|
||||
a pointers.
|
||||
|
||||
But the functions are declared taking pointers to des_cblock, i.e.
|
||||
pointers to arrays. And on the other hand, they take plain
|
||||
des_key_schedule arguments, which is equivalent to pointers to
|
||||
struct des_ctx. */
|
||||
void
|
||||
des_ecb3_encrypt(const_des_cblock *src, des_cblock *dst,
|
||||
des_key_schedule k1,
|
||||
des_key_schedule k2,
|
||||
des_key_schedule k3, int enc);
|
||||
|
||||
/* des_cbc_cksum in libdes returns a 32 bit integer, representing the
|
||||
* latter half of the output block, using little endian byte order. */
|
||||
uint32_t
|
||||
des_cbc_cksum(const uint8_t *src, des_cblock *dst,
|
||||
long length, des_key_schedule ctx,
|
||||
const_des_cblock *iv);
|
||||
|
||||
/* NOTE: Doesn't update iv. */
|
||||
void
|
||||
des_cbc_encrypt(const_des_cblock *src, des_cblock *dst, long length,
|
||||
des_key_schedule ctx, const_des_cblock *iv,
|
||||
int enc);
|
||||
|
||||
/* Similar, but updates iv. */
|
||||
void
|
||||
des_ncbc_encrypt(const_des_cblock *src, des_cblock *dst, long length,
|
||||
des_key_schedule ctx, des_cblock *iv,
|
||||
int enc);
|
||||
|
||||
void
|
||||
des_ecb_encrypt(const_des_cblock *src, des_cblock *dst,
|
||||
des_key_schedule ctx, int enc);
|
||||
|
||||
void
|
||||
des_ede3_cbc_encrypt(const_des_cblock *src, des_cblock *dst, long length,
|
||||
des_key_schedule k1,
|
||||
des_key_schedule k2,
|
||||
des_key_schedule k3,
|
||||
des_cblock *iv,
|
||||
int enc);
|
||||
|
||||
int
|
||||
des_set_odd_parity(des_cblock *key);
|
||||
|
||||
int
|
||||
des_key_sched(const_des_cblock *key, des_key_schedule ctx);
|
||||
|
||||
int
|
||||
des_is_weak_key(const_des_cblock *key);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* NETTLE_DES_COMPAT_H_INCLUDED */
|
||||
@@ -1,120 +0,0 @@
|
||||
/* des.h
|
||||
|
||||
The des block cipher. And triple des.
|
||||
|
||||
Copyright (C) 1992 Dana L. How
|
||||
Copyright (C) 2001 Niels Möller
|
||||
|
||||
This file is part of GNU Nettle.
|
||||
|
||||
GNU Nettle is free software: you can redistribute it and/or
|
||||
modify it under the terms of either:
|
||||
|
||||
* the GNU Lesser General Public License as published by the Free
|
||||
Software Foundation; either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or
|
||||
|
||||
* the GNU General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or both in parallel, as here.
|
||||
|
||||
GNU Nettle is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received copies of the GNU General Public License and
|
||||
the GNU Lesser General Public License along with this program. If
|
||||
not, see http://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
/*
|
||||
* des - fast & portable DES encryption & decryption.
|
||||
* Copyright (C) 1992 Dana L. How
|
||||
* Please see the file `../lib/descore.README' for the complete copyright
|
||||
* notice.
|
||||
*
|
||||
* Slightly edited by Niels Möller, 1997
|
||||
*/
|
||||
|
||||
#ifndef NETTLE_DES_H_INCLUDED
|
||||
#define NETTLE_DES_H_INCLUDED
|
||||
|
||||
#include "nettle-types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Namespace mangling */
|
||||
#define des_set_key nettle_des_set_key
|
||||
#define des_encrypt nettle_des_encrypt
|
||||
#define des_decrypt nettle_des_decrypt
|
||||
#define des_check_parity nettle_des_check_parity
|
||||
#define des_fix_parity nettle_des_fix_parity
|
||||
#define des3_set_key nettle_des3_set_key
|
||||
#define des3_encrypt nettle_des3_encrypt
|
||||
#define des3_decrypt nettle_des3_decrypt
|
||||
|
||||
#define DES_KEY_SIZE 8
|
||||
#define DES_BLOCK_SIZE 8
|
||||
|
||||
/* Expanded key length */
|
||||
#define _DES_KEY_LENGTH 32
|
||||
|
||||
struct des_ctx
|
||||
{
|
||||
uint32_t key[_DES_KEY_LENGTH];
|
||||
};
|
||||
|
||||
/* Returns 1 for good keys and 0 for weak keys. */
|
||||
int
|
||||
des_set_key(struct des_ctx *ctx, const uint8_t *key);
|
||||
|
||||
void
|
||||
des_encrypt(const struct des_ctx *ctx,
|
||||
size_t length, uint8_t *dst,
|
||||
const uint8_t *src);
|
||||
void
|
||||
des_decrypt(const struct des_ctx *ctx,
|
||||
size_t length, uint8_t *dst,
|
||||
const uint8_t *src);
|
||||
|
||||
int
|
||||
des_check_parity(size_t length, const uint8_t *key);
|
||||
|
||||
void
|
||||
des_fix_parity(size_t length, uint8_t *dst,
|
||||
const uint8_t *src);
|
||||
|
||||
#define DES3_KEY_SIZE 24
|
||||
#define DES3_BLOCK_SIZE DES_BLOCK_SIZE
|
||||
|
||||
struct des3_ctx
|
||||
{
|
||||
struct des_ctx des[3];
|
||||
};
|
||||
|
||||
|
||||
/* Returns 1 for good keys and 0 for weak keys. */
|
||||
int
|
||||
des3_set_key(struct des3_ctx *ctx, const uint8_t *key);
|
||||
|
||||
void
|
||||
des3_encrypt(const struct des3_ctx *ctx,
|
||||
size_t length, uint8_t *dst,
|
||||
const uint8_t *src);
|
||||
void
|
||||
des3_decrypt(const struct des3_ctx *ctx,
|
||||
size_t length, uint8_t *dst,
|
||||
const uint8_t *src);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* NETTLE_DES_H_INCLUDED */
|
||||
@@ -1,183 +0,0 @@
|
||||
/* dsa-compat.h
|
||||
|
||||
Old DSA publickey interface.
|
||||
|
||||
Copyright (C) 2002, 2013, 2014 Niels Möller
|
||||
|
||||
This file is part of GNU Nettle.
|
||||
|
||||
GNU Nettle is free software: you can redistribute it and/or
|
||||
modify it under the terms of either:
|
||||
|
||||
* the GNU Lesser General Public License as published by the Free
|
||||
Software Foundation; either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or
|
||||
|
||||
* the GNU General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or both in parallel, as here.
|
||||
|
||||
GNU Nettle is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received copies of the GNU General Public License and
|
||||
the GNU Lesser General Public License along with this program. If
|
||||
not, see http://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
#ifndef NETTLE_DSA_COMPAT_H_INCLUDED
|
||||
#define NETTLE_DSA_COMPAT_H_INCLUDED
|
||||
|
||||
#include "dsa.h"
|
||||
|
||||
#include "sha1.h"
|
||||
#include "sha2.h"
|
||||
|
||||
/* Name mangling */
|
||||
#define dsa_public_key_init nettle_dsa_public_key_init
|
||||
#define dsa_public_key_clear nettle_dsa_public_key_clear
|
||||
#define dsa_private_key_init nettle_dsa_private_key_init
|
||||
#define dsa_private_key_clear nettle_dsa_private_key_clear
|
||||
#define dsa_sha1_sign nettle_dsa_sha1_sign
|
||||
#define dsa_sha1_verify nettle_dsa_sha1_verify
|
||||
#define dsa_sha256_sign nettle_dsa_sha256_sign
|
||||
#define dsa_sha256_verify nettle_dsa_sha256_verify
|
||||
#define dsa_sha1_sign_digest nettle_dsa_sha1_sign_digest
|
||||
#define dsa_sha1_verify_digest nettle_dsa_sha1_verify_digest
|
||||
#define dsa_sha256_sign_digest nettle_dsa_sha256_sign_digest
|
||||
#define dsa_sha256_verify_digest nettle_dsa_sha256_verify_digest
|
||||
#define dsa_compat_generate_keypair nettle_dsa_compat_generate_keypair
|
||||
|
||||
/* Switch meaning of dsa_generate_keypair */
|
||||
#undef dsa_generate_keypair
|
||||
#define dsa_generate_keypair nettle_dsa_compat_generate_keypair
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct dsa_public_key
|
||||
{
|
||||
/* Same as struct dsa_params, but can't use that struct here without
|
||||
breaking backwards compatibility. Layout must be identical, since
|
||||
this is cast to a struct dsa_param pointer for calling _dsa_sign
|
||||
and _dsa_verify */
|
||||
mpz_t p;
|
||||
mpz_t q;
|
||||
mpz_t g;
|
||||
|
||||
/* Public value */
|
||||
mpz_t y;
|
||||
};
|
||||
|
||||
struct dsa_private_key
|
||||
{
|
||||
/* Unlike an rsa public key, private key operations will need both
|
||||
* the private and the public information. */
|
||||
mpz_t x;
|
||||
};
|
||||
|
||||
/* Signing a message works as follows:
|
||||
*
|
||||
* Store the private key in a dsa_private_key struct.
|
||||
*
|
||||
* Initialize a hashing context, by callling
|
||||
* sha1_init
|
||||
*
|
||||
* Hash the message by calling
|
||||
* sha1_update
|
||||
*
|
||||
* Create the signature by calling
|
||||
* dsa_sha1_sign
|
||||
*
|
||||
* The signature is represented as a struct dsa_signature. This call also
|
||||
* resets the hashing context.
|
||||
*
|
||||
* When done with the key and signature, don't forget to call
|
||||
* dsa_signature_clear.
|
||||
*/
|
||||
|
||||
/* Calls mpz_init to initialize bignum storage. */
|
||||
void
|
||||
dsa_public_key_init(struct dsa_public_key *key);
|
||||
|
||||
/* Calls mpz_clear to deallocate bignum storage. */
|
||||
void
|
||||
dsa_public_key_clear(struct dsa_public_key *key);
|
||||
|
||||
|
||||
/* Calls mpz_init to initialize bignum storage. */
|
||||
void
|
||||
dsa_private_key_init(struct dsa_private_key *key);
|
||||
|
||||
/* Calls mpz_clear to deallocate bignum storage. */
|
||||
void
|
||||
dsa_private_key_clear(struct dsa_private_key *key);
|
||||
|
||||
int
|
||||
dsa_sha1_sign(const struct dsa_public_key *pub,
|
||||
const struct dsa_private_key *key,
|
||||
void *random_ctx, nettle_random_func *random,
|
||||
struct sha1_ctx *hash,
|
||||
struct dsa_signature *signature);
|
||||
|
||||
int
|
||||
dsa_sha256_sign(const struct dsa_public_key *pub,
|
||||
const struct dsa_private_key *key,
|
||||
void *random_ctx, nettle_random_func *random,
|
||||
struct sha256_ctx *hash,
|
||||
struct dsa_signature *signature);
|
||||
|
||||
int
|
||||
dsa_sha1_verify(const struct dsa_public_key *key,
|
||||
struct sha1_ctx *hash,
|
||||
const struct dsa_signature *signature);
|
||||
|
||||
int
|
||||
dsa_sha256_verify(const struct dsa_public_key *key,
|
||||
struct sha256_ctx *hash,
|
||||
const struct dsa_signature *signature);
|
||||
|
||||
int
|
||||
dsa_sha1_sign_digest(const struct dsa_public_key *pub,
|
||||
const struct dsa_private_key *key,
|
||||
void *random_ctx, nettle_random_func *random,
|
||||
const uint8_t *digest,
|
||||
struct dsa_signature *signature);
|
||||
int
|
||||
dsa_sha256_sign_digest(const struct dsa_public_key *pub,
|
||||
const struct dsa_private_key *key,
|
||||
void *random_ctx, nettle_random_func *random,
|
||||
const uint8_t *digest,
|
||||
struct dsa_signature *signature);
|
||||
|
||||
int
|
||||
dsa_sha1_verify_digest(const struct dsa_public_key *key,
|
||||
const uint8_t *digest,
|
||||
const struct dsa_signature *signature);
|
||||
|
||||
int
|
||||
dsa_sha256_verify_digest(const struct dsa_public_key *key,
|
||||
const uint8_t *digest,
|
||||
const struct dsa_signature *signature);
|
||||
|
||||
/* Key generation */
|
||||
int
|
||||
dsa_generate_keypair(struct dsa_public_key *pub,
|
||||
struct dsa_private_key *key,
|
||||
|
||||
void *random_ctx, nettle_random_func *random,
|
||||
void *progress_ctx, nettle_progress_func *progress,
|
||||
unsigned p_bits, unsigned q_bits);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* NETTLE_DSA_COMPAT_H_INCLUDED */
|
||||
@@ -1,216 +0,0 @@
|
||||
/* dsa.h
|
||||
|
||||
The DSA publickey algorithm.
|
||||
|
||||
Copyright (C) 2002, 2013, 2014 Niels Möller
|
||||
|
||||
This file is part of GNU Nettle.
|
||||
|
||||
GNU Nettle is free software: you can redistribute it and/or
|
||||
modify it under the terms of either:
|
||||
|
||||
* the GNU Lesser General Public License as published by the Free
|
||||
Software Foundation; either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or
|
||||
|
||||
* the GNU General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or both in parallel, as here.
|
||||
|
||||
GNU Nettle is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received copies of the GNU General Public License and
|
||||
the GNU Lesser General Public License along with this program. If
|
||||
not, see http://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
#ifndef NETTLE_DSA_H_INCLUDED
|
||||
#define NETTLE_DSA_H_INCLUDED
|
||||
|
||||
#include "nettle-types.h"
|
||||
#include "bignum.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Name mangling */
|
||||
#define dsa_params_init nettle_dsa_params_init
|
||||
#define dsa_params_clear nettle_dsa_params_clear
|
||||
#define dsa_signature_init nettle_dsa_signature_init
|
||||
#define dsa_signature_clear nettle_dsa_signature_clear
|
||||
#define dsa_sign nettle_dsa_sign
|
||||
#define dsa_verify nettle_dsa_verify
|
||||
#define dsa_generate_params nettle_dsa_generate_params
|
||||
#define dsa_generate_keypair nettle_dsa_generate_keypair
|
||||
#define dsa_signature_from_sexp nettle_dsa_signature_from_sexp
|
||||
#define dsa_keypair_to_sexp nettle_dsa_keypair_to_sexp
|
||||
#define dsa_keypair_from_sexp_alist nettle_dsa_keypair_from_sexp_alist
|
||||
#define dsa_sha1_keypair_from_sexp nettle_dsa_sha1_keypair_from_sexp
|
||||
#define dsa_sha256_keypair_from_sexp nettle_dsa_sha256_keypair_from_sexp
|
||||
#define dsa_params_from_der_iterator nettle_dsa_params_from_der_iterator
|
||||
#define dsa_public_key_from_der_iterator nettle_dsa_public_key_from_der_iterator
|
||||
#define dsa_openssl_private_key_from_der_iterator nettle_dsa_openssl_private_key_from_der_iterator
|
||||
#define dsa_openssl_private_key_from_der nettle_openssl_provate_key_from_der
|
||||
#define _dsa_hash _nettle_dsa_hash
|
||||
|
||||
/* For FIPS approved parameters */
|
||||
#define DSA_SHA1_MIN_P_BITS 512
|
||||
#define DSA_SHA1_Q_OCTETS 20
|
||||
#define DSA_SHA1_Q_BITS 160
|
||||
|
||||
#define DSA_SHA256_MIN_P_BITS 1024
|
||||
#define DSA_SHA256_Q_OCTETS 32
|
||||
#define DSA_SHA256_Q_BITS 256
|
||||
|
||||
struct dsa_params
|
||||
{
|
||||
/* Modulo */
|
||||
mpz_t p;
|
||||
|
||||
/* Group order */
|
||||
mpz_t q;
|
||||
|
||||
/* Generator */
|
||||
mpz_t g;
|
||||
};
|
||||
|
||||
void
|
||||
dsa_params_init (struct dsa_params *params);
|
||||
|
||||
void
|
||||
dsa_params_clear (struct dsa_params *params);
|
||||
|
||||
struct dsa_signature
|
||||
{
|
||||
mpz_t r;
|
||||
mpz_t s;
|
||||
};
|
||||
|
||||
/* Calls mpz_init to initialize bignum storage. */
|
||||
void
|
||||
dsa_signature_init(struct dsa_signature *signature);
|
||||
|
||||
/* Calls mpz_clear to deallocate bignum storage. */
|
||||
void
|
||||
dsa_signature_clear(struct dsa_signature *signature);
|
||||
|
||||
int
|
||||
dsa_sign(const struct dsa_params *params,
|
||||
const mpz_t x,
|
||||
void *random_ctx, nettle_random_func *random,
|
||||
size_t digest_size,
|
||||
const uint8_t *digest,
|
||||
struct dsa_signature *signature);
|
||||
|
||||
int
|
||||
dsa_verify(const struct dsa_params *params,
|
||||
const mpz_t y,
|
||||
size_t digest_size,
|
||||
const uint8_t *digest,
|
||||
const struct dsa_signature *signature);
|
||||
|
||||
|
||||
/* Key generation */
|
||||
|
||||
int
|
||||
dsa_generate_params(struct dsa_params *params,
|
||||
void *random_ctx, nettle_random_func *random,
|
||||
void *progress_ctx, nettle_progress_func *progress,
|
||||
unsigned p_bits, unsigned q_bits);
|
||||
|
||||
void
|
||||
dsa_generate_keypair (const struct dsa_params *params,
|
||||
mpz_t pub, mpz_t key,
|
||||
void *random_ctx, nettle_random_func *random);
|
||||
|
||||
/* Keys in sexp form. */
|
||||
|
||||
struct nettle_buffer;
|
||||
|
||||
/* Generates a public-key expression if PRIV is NULL .*/
|
||||
int
|
||||
dsa_keypair_to_sexp(struct nettle_buffer *buffer,
|
||||
const char *algorithm_name, /* NULL means "dsa" */
|
||||
const struct dsa_params *params,
|
||||
const mpz_t pub,
|
||||
const mpz_t priv);
|
||||
|
||||
struct sexp_iterator;
|
||||
|
||||
int
|
||||
dsa_signature_from_sexp(struct dsa_signature *rs,
|
||||
struct sexp_iterator *i,
|
||||
unsigned q_bits);
|
||||
|
||||
int
|
||||
dsa_keypair_from_sexp_alist(struct dsa_params *params,
|
||||
mpz_t pub,
|
||||
mpz_t priv,
|
||||
unsigned p_max_bits,
|
||||
unsigned q_bits,
|
||||
struct sexp_iterator *i);
|
||||
|
||||
/* If PRIV is NULL, expect a public-key expression. If PUB is NULL,
|
||||
* expect a private key expression and ignore the parts not needed for
|
||||
* the public key. */
|
||||
/* Keys must be initialized before calling this function, as usual. */
|
||||
int
|
||||
dsa_sha1_keypair_from_sexp(struct dsa_params *params,
|
||||
mpz_t pub,
|
||||
mpz_t priv,
|
||||
unsigned p_max_bits,
|
||||
size_t length, const uint8_t *expr);
|
||||
|
||||
int
|
||||
dsa_sha256_keypair_from_sexp(struct dsa_params *params,
|
||||
mpz_t pub,
|
||||
mpz_t priv,
|
||||
unsigned p_max_bits,
|
||||
size_t length, const uint8_t *expr);
|
||||
|
||||
/* Keys in X.509 andd OpenSSL format. */
|
||||
struct asn1_der_iterator;
|
||||
|
||||
int
|
||||
dsa_params_from_der_iterator(struct dsa_params *params,
|
||||
unsigned max_bits, unsigned q_bits,
|
||||
struct asn1_der_iterator *i);
|
||||
|
||||
int
|
||||
dsa_public_key_from_der_iterator(const struct dsa_params *params,
|
||||
mpz_t pub,
|
||||
struct asn1_der_iterator *i);
|
||||
|
||||
int
|
||||
dsa_openssl_private_key_from_der_iterator(struct dsa_params *params,
|
||||
mpz_t pub,
|
||||
mpz_t priv,
|
||||
unsigned p_max_bits,
|
||||
struct asn1_der_iterator *i);
|
||||
|
||||
int
|
||||
dsa_openssl_private_key_from_der(struct dsa_params *params,
|
||||
mpz_t pub,
|
||||
mpz_t priv,
|
||||
unsigned p_max_bits,
|
||||
size_t length, const uint8_t *data);
|
||||
|
||||
|
||||
/* Internal functions. */
|
||||
void
|
||||
_dsa_hash (mpz_t h, unsigned bit_size,
|
||||
size_t length, const uint8_t *digest);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* NETTLE_DSA_H_INCLUDED */
|
||||
@@ -1,185 +0,0 @@
|
||||
/* eax.h
|
||||
|
||||
EAX mode, see http://www.cs.ucdavis.edu/~rogaway/papers/eax.pdf
|
||||
|
||||
Copyright (C) 2013 Niels Möller
|
||||
|
||||
This file is part of GNU Nettle.
|
||||
|
||||
GNU Nettle is free software: you can redistribute it and/or
|
||||
modify it under the terms of either:
|
||||
|
||||
* the GNU Lesser General Public License as published by the Free
|
||||
Software Foundation; either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or
|
||||
|
||||
* the GNU General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or both in parallel, as here.
|
||||
|
||||
GNU Nettle is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received copies of the GNU General Public License and
|
||||
the GNU Lesser General Public License along with this program. If
|
||||
not, see http://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
#ifndef NETTLE_EAX_H_INCLUDED
|
||||
#define NETTLE_EAX_H_INCLUDED
|
||||
|
||||
#include "aes.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Name mangling */
|
||||
#define eax_set_key nettle_eax_set_key
|
||||
#define eax_set_nonce nettle_eax_set_nonce
|
||||
#define eax_update nettle_eax_update
|
||||
#define eax_encrypt nettle_eax_encrypt
|
||||
#define eax_decrypt nettle_eax_decrypt
|
||||
#define eax_digest nettle_eax_digest
|
||||
|
||||
#define eax_aes128_set_key nettle_eax_aes128_set_key
|
||||
#define eax_aes128_set_nonce nettle_eax_aes128_set_nonce
|
||||
#define eax_aes128_update nettle_eax_aes128_update
|
||||
#define eax_aes128_encrypt nettle_eax_aes128_encrypt
|
||||
#define eax_aes128_decrypt nettle_eax_aes128_decrypt
|
||||
#define eax_aes128_digest nettle_eax_aes128_digest
|
||||
|
||||
/* Restricted to block ciphers with 128 bit block size. FIXME: Reflect
|
||||
this in naming? */
|
||||
|
||||
#define EAX_BLOCK_SIZE 16
|
||||
#define EAX_DIGEST_SIZE 16
|
||||
/* FIXME: Reasonable default? */
|
||||
#define EAX_IV_SIZE 16
|
||||
|
||||
/* Values independent of message and nonce */
|
||||
struct eax_key
|
||||
{
|
||||
union nettle_block16 pad_block;
|
||||
union nettle_block16 pad_partial;
|
||||
};
|
||||
|
||||
struct eax_ctx
|
||||
{
|
||||
union nettle_block16 omac_nonce;
|
||||
union nettle_block16 omac_data;
|
||||
union nettle_block16 omac_message;
|
||||
union nettle_block16 ctr;
|
||||
};
|
||||
|
||||
void
|
||||
eax_set_key (struct eax_key *key, const void *cipher, nettle_cipher_func *f);
|
||||
|
||||
void
|
||||
eax_set_nonce (struct eax_ctx *eax, const struct eax_key *key,
|
||||
const void *cipher, nettle_cipher_func *f,
|
||||
size_t nonce_length, const uint8_t *nonce);
|
||||
|
||||
void
|
||||
eax_update (struct eax_ctx *eax, const struct eax_key *key,
|
||||
const void *cipher, nettle_cipher_func *f,
|
||||
size_t data_length, const uint8_t *data);
|
||||
|
||||
void
|
||||
eax_encrypt (struct eax_ctx *eax, const struct eax_key *key,
|
||||
const void *cipher, nettle_cipher_func *f,
|
||||
size_t length, uint8_t *dst, const uint8_t *src);
|
||||
|
||||
void
|
||||
eax_decrypt (struct eax_ctx *eax, const struct eax_key *key,
|
||||
const void *cipher, nettle_cipher_func *f,
|
||||
size_t length, uint8_t *dst, const uint8_t *src);
|
||||
|
||||
void
|
||||
eax_digest (struct eax_ctx *eax, const struct eax_key *key,
|
||||
const void *cipher, nettle_cipher_func *f,
|
||||
size_t length, uint8_t *digest);
|
||||
|
||||
/* Put the cipher last, to get cipher-independent offsets for the EAX
|
||||
* state. */
|
||||
#define EAX_CTX(type) \
|
||||
{ struct eax_key key; struct eax_ctx eax; type cipher; }
|
||||
|
||||
#define EAX_SET_KEY(ctx, set_key, encrypt, data) \
|
||||
do { \
|
||||
(set_key)(&(ctx)->cipher, (data)); \
|
||||
if (0) (encrypt) (&(ctx)->cipher, ~(size_t) 0, \
|
||||
(uint8_t *) 0, (const uint8_t *) 0); \
|
||||
eax_set_key (&(ctx)->key, &(ctx)->cipher, (nettle_cipher_func *) encrypt); \
|
||||
} while (0)
|
||||
|
||||
#define EAX_SET_NONCE(ctx, encrypt, length, nonce) \
|
||||
(0 ? (encrypt) (&(ctx)->cipher, ~(size_t) 0, \
|
||||
(uint8_t *) 0, (const uint8_t *) 0) \
|
||||
: eax_set_nonce (&(ctx)->eax, &(ctx)->key, \
|
||||
&(ctx)->cipher, (nettle_cipher_func *) (encrypt), \
|
||||
(length), (nonce)))
|
||||
|
||||
#define EAX_UPDATE(ctx, encrypt, length, data) \
|
||||
(0 ? (encrypt) (&(ctx)->cipher, ~(size_t) 0, \
|
||||
(uint8_t *) 0, (const uint8_t *) 0) \
|
||||
: eax_update (&(ctx)->eax, &(ctx)->key, \
|
||||
&(ctx)->cipher, (nettle_cipher_func *) (encrypt), \
|
||||
(length), (data)))
|
||||
|
||||
#define EAX_ENCRYPT(ctx, encrypt, length, dst, src) \
|
||||
(0 ? (encrypt) (&(ctx)->cipher, ~(size_t) 0, \
|
||||
(uint8_t *) 0, (const uint8_t *) 0) \
|
||||
: eax_encrypt (&(ctx)->eax, &(ctx)->key, \
|
||||
&(ctx)->cipher, (nettle_cipher_func *) (encrypt), \
|
||||
(length), (dst), (src)))
|
||||
|
||||
#define EAX_DECRYPT(ctx, encrypt, length, dst, src) \
|
||||
(0 ? (encrypt) (&(ctx)->cipher, ~(size_t) 0, \
|
||||
(uint8_t *) 0, (const uint8_t *) 0) \
|
||||
: eax_decrypt (&(ctx)->eax, &(ctx)->key, \
|
||||
&(ctx)->cipher, (nettle_cipher_func *) (encrypt), \
|
||||
(length), (dst), (src)))
|
||||
|
||||
#define EAX_DIGEST(ctx, encrypt, length, digest) \
|
||||
(0 ? (encrypt) (&(ctx)->cipher, ~(size_t) 0, \
|
||||
(uint8_t *) 0, (const uint8_t *) 0) \
|
||||
: eax_digest (&(ctx)->eax, &(ctx)->key, \
|
||||
&(ctx)->cipher, (nettle_cipher_func *) (encrypt), \
|
||||
(length), (digest)))
|
||||
|
||||
struct eax_aes128_ctx EAX_CTX(struct aes128_ctx);
|
||||
|
||||
void
|
||||
eax_aes128_set_key(struct eax_aes128_ctx *ctx, const uint8_t *key);
|
||||
|
||||
void
|
||||
eax_aes128_set_nonce(struct eax_aes128_ctx *ctx,
|
||||
size_t length, const uint8_t *iv);
|
||||
|
||||
void
|
||||
eax_aes128_update(struct eax_aes128_ctx *ctx,
|
||||
size_t length, const uint8_t *data);
|
||||
|
||||
void
|
||||
eax_aes128_encrypt(struct eax_aes128_ctx *ctx,
|
||||
size_t length, uint8_t *dst, const uint8_t *src);
|
||||
|
||||
void
|
||||
eax_aes128_decrypt(struct eax_aes128_ctx *ctx,
|
||||
size_t length, uint8_t *dst, const uint8_t *src);
|
||||
|
||||
void
|
||||
eax_aes128_digest(struct eax_aes128_ctx *ctx, size_t length, uint8_t *digest);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* NETTLE_EAX_H_INCLUDED */
|
||||
@@ -1,71 +0,0 @@
|
||||
/* ecc-curve.h
|
||||
|
||||
Copyright (C) 2013 Niels Möller
|
||||
|
||||
This file is part of GNU Nettle.
|
||||
|
||||
GNU Nettle is free software: you can redistribute it and/or
|
||||
modify it under the terms of either:
|
||||
|
||||
* the GNU Lesser General Public License as published by the Free
|
||||
Software Foundation; either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or
|
||||
|
||||
* the GNU General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or both in parallel, as here.
|
||||
|
||||
GNU Nettle is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received copies of the GNU General Public License and
|
||||
the GNU Lesser General Public License along with this program. If
|
||||
not, see http://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
/* Development of Nettle's ECC support was funded by the .SE Internet Fund. */
|
||||
|
||||
#ifndef NETTLE_ECC_CURVE_H_INCLUDED
|
||||
#define NETTLE_ECC_CURVE_H_INCLUDED
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* The contents of this struct is internal. */
|
||||
struct ecc_curve;
|
||||
|
||||
/* FIXME: Rename with leading underscore. Due to ABI subtleties,
|
||||
applications should not refer to these directly, but use the below
|
||||
accessor functions. */
|
||||
extern const struct ecc_curve nettle_secp_192r1;
|
||||
extern const struct ecc_curve nettle_secp_224r1;
|
||||
extern const struct ecc_curve nettle_secp_256r1;
|
||||
extern const struct ecc_curve nettle_secp_384r1;
|
||||
extern const struct ecc_curve nettle_secp_521r1;
|
||||
|
||||
#ifdef __GNUC__
|
||||
#define NETTLE_PURE __attribute__((pure))
|
||||
#else
|
||||
#define NETTLE_PURE
|
||||
#endif
|
||||
|
||||
const struct ecc_curve * NETTLE_PURE nettle_get_secp_192r1(void);
|
||||
const struct ecc_curve * NETTLE_PURE nettle_get_secp_224r1(void);
|
||||
const struct ecc_curve * NETTLE_PURE nettle_get_secp_256r1(void);
|
||||
const struct ecc_curve * NETTLE_PURE nettle_get_secp_384r1(void);
|
||||
const struct ecc_curve * NETTLE_PURE nettle_get_secp_521r1(void);
|
||||
|
||||
#undef NETTLE_PURE
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* NETTLE_ECC_CURVE_H_INCLUDED */
|
||||
@@ -1,159 +0,0 @@
|
||||
/* ecc.h
|
||||
|
||||
Copyright (C) 2013 Niels Möller
|
||||
|
||||
This file is part of GNU Nettle.
|
||||
|
||||
GNU Nettle is free software: you can redistribute it and/or
|
||||
modify it under the terms of either:
|
||||
|
||||
* the GNU Lesser General Public License as published by the Free
|
||||
Software Foundation; either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or
|
||||
|
||||
* the GNU General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or both in parallel, as here.
|
||||
|
||||
GNU Nettle is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received copies of the GNU General Public License and
|
||||
the GNU Lesser General Public License along with this program. If
|
||||
not, see http://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
/* Development of Nettle's ECC support was funded by the .SE Internet Fund. */
|
||||
|
||||
#ifndef NETTLE_ECC_H_INCLUDED
|
||||
#define NETTLE_ECC_H_INCLUDED
|
||||
|
||||
#include "nettle-types.h"
|
||||
#include "bignum.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Name mangling */
|
||||
#define ecc_point_init nettle_ecc_point_init
|
||||
#define ecc_point_clear nettle_ecc_point_clear
|
||||
#define ecc_point_set nettle_ecc_point_set
|
||||
#define ecc_point_get nettle_ecc_point_get
|
||||
#define ecc_point_mul nettle_ecc_point_mul
|
||||
#define ecc_point_mul_g nettle_ecc_point_mul_g
|
||||
#define ecc_scalar_init nettle_ecc_scalar_init
|
||||
#define ecc_scalar_clear nettle_ecc_scalar_clear
|
||||
#define ecc_scalar_set nettle_ecc_scalar_set
|
||||
#define ecc_scalar_get nettle_ecc_scalar_get
|
||||
#define ecc_scalar_random nettle_ecc_scalar_random
|
||||
#define ecc_point_mul nettle_ecc_point_mul
|
||||
#define ecc_bit_size nettle_ecc_bit_size
|
||||
#define ecc_size nettle_ecc_size
|
||||
#define ecc_size_a nettle_ecc_size_a
|
||||
#define ecc_size_j nettle_ecc_size_j
|
||||
|
||||
struct ecc_curve;
|
||||
|
||||
/* High level interface, for ECDSA, DH, etc */
|
||||
|
||||
/* Represents a point on the ECC curve */
|
||||
struct ecc_point
|
||||
{
|
||||
const struct ecc_curve *ecc;
|
||||
/* Allocated using the same allocation function as GMP. */
|
||||
mp_limb_t *p;
|
||||
};
|
||||
|
||||
/* Represents a non-zero scalar, an element of Z_q^*, where q is the
|
||||
group order of the curve. */
|
||||
struct ecc_scalar
|
||||
{
|
||||
const struct ecc_curve *ecc;
|
||||
/* Allocated using the same allocation function as GMP. */
|
||||
mp_limb_t *p;
|
||||
};
|
||||
|
||||
void
|
||||
ecc_point_init (struct ecc_point *p, const struct ecc_curve *ecc);
|
||||
void
|
||||
ecc_point_clear (struct ecc_point *p);
|
||||
|
||||
/* Fails and returns zero if the point is not on the curve. */
|
||||
int
|
||||
ecc_point_set (struct ecc_point *p, const mpz_t x, const mpz_t y);
|
||||
void
|
||||
ecc_point_get (const struct ecc_point *p, mpz_t x, mpz_t y);
|
||||
|
||||
void
|
||||
ecc_scalar_init (struct ecc_scalar *s, const struct ecc_curve *ecc);
|
||||
void
|
||||
ecc_scalar_clear (struct ecc_scalar *s);
|
||||
|
||||
/* Fails and returns zero if the scalar is not in the proper range. */
|
||||
int
|
||||
ecc_scalar_set (struct ecc_scalar *s, const mpz_t z);
|
||||
void
|
||||
ecc_scalar_get (const struct ecc_scalar *s, mpz_t z);
|
||||
/* Generates a random scalar, suitable as an ECDSA private key or a
|
||||
ECDH exponent. */
|
||||
void
|
||||
ecc_scalar_random (struct ecc_scalar *s,
|
||||
void *random_ctx, nettle_random_func *random);
|
||||
|
||||
/* Computes r = n p */
|
||||
void
|
||||
ecc_point_mul (struct ecc_point *r, const struct ecc_scalar *n,
|
||||
const struct ecc_point *p);
|
||||
|
||||
/* Computes r = n g */
|
||||
void
|
||||
ecc_point_mul_g (struct ecc_point *r, const struct ecc_scalar *n);
|
||||
|
||||
|
||||
/* Low-level interface */
|
||||
|
||||
/* Points on a curve are represented as arrays of mp_limb_t, with
|
||||
curve-specific representation. For the secp curves, we use Jacobian
|
||||
coordinates (possibly in Montgomery form for mod multiplication).
|
||||
For curve25519 we use homogeneous coordinates on an equivalent
|
||||
Edwards curve. The suffix "_h" denotes this internal
|
||||
representation.
|
||||
|
||||
Since we use additive notation for the groups, the infinity point
|
||||
on the curve is denoted 0. The infinity point can be represented
|
||||
with x = y = 0 in affine coordinates, and Z = 0 in Jacobian
|
||||
coordinates. However, note that most of the ECC functions do *not*
|
||||
support infinity as an input or output.
|
||||
*/
|
||||
|
||||
/* Returns the bit size of a single coordinate (and of the prime p). */
|
||||
unsigned
|
||||
ecc_bit_size (const struct ecc_curve *ecc);
|
||||
|
||||
/* Returns the size of a single coordinate. */
|
||||
mp_size_t
|
||||
ecc_size (const struct ecc_curve *ecc);
|
||||
|
||||
/* Size of a point, using affine coordinates x, y. */
|
||||
mp_size_t
|
||||
ecc_size_a (const struct ecc_curve *ecc);
|
||||
|
||||
/* Size of a point, using jacobian coordinates X, Y and Z. */
|
||||
mp_size_t
|
||||
ecc_size_j (const struct ecc_curve *ecc);
|
||||
|
||||
/* FIXME: Define a generic ecc_dup, ecc_add, for any type of curve. Do
|
||||
they need to handle infinity points? */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* NETTLE_ECC_H_INCLUDED */
|
||||
@@ -1,103 +0,0 @@
|
||||
/* ecdsa.h
|
||||
|
||||
Copyright (C) 2013 Niels Möller
|
||||
|
||||
This file is part of GNU Nettle.
|
||||
|
||||
GNU Nettle is free software: you can redistribute it and/or
|
||||
modify it under the terms of either:
|
||||
|
||||
* the GNU Lesser General Public License as published by the Free
|
||||
Software Foundation; either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or
|
||||
|
||||
* the GNU General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or both in parallel, as here.
|
||||
|
||||
GNU Nettle is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received copies of the GNU General Public License and
|
||||
the GNU Lesser General Public License along with this program. If
|
||||
not, see http://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
/* Development of Nettle's ECC support was funded by the .SE Internet Fund. */
|
||||
|
||||
#ifndef NETTLE_ECDSA_H_INCLUDED
|
||||
#define NETTLE_ECDSA_H_INCLUDED
|
||||
|
||||
#include "ecc.h"
|
||||
#include "dsa.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Name mangling */
|
||||
#define ecdsa_sign nettle_ecdsa_sign
|
||||
#define ecdsa_verify nettle_ecdsa_verify
|
||||
#define ecdsa_generate_keypair nettle_ecdsa_generate_keypair
|
||||
#define ecc_ecdsa_sign nettle_ecc_ecdsa_sign
|
||||
#define ecc_ecdsa_sign_itch nettle_ecc_ecdsa_sign_itch
|
||||
#define ecc_ecdsa_verify nettle_ecc_ecdsa_verify
|
||||
#define ecc_ecdsa_verify_itch nettle_ecc_ecdsa_verify_itch
|
||||
|
||||
/* High level ECDSA functions.
|
||||
*
|
||||
* A public key is represented as a struct ecc_point, and a private
|
||||
* key as a struct ecc_scalar. FIXME: Introduce some aliases? */
|
||||
void
|
||||
ecdsa_sign (const struct ecc_scalar *key,
|
||||
void *random_ctx, nettle_random_func *random,
|
||||
size_t digest_length,
|
||||
const uint8_t *digest,
|
||||
struct dsa_signature *signature);
|
||||
|
||||
int
|
||||
ecdsa_verify (const struct ecc_point *pub,
|
||||
size_t length, const uint8_t *digest,
|
||||
const struct dsa_signature *signature);
|
||||
|
||||
void
|
||||
ecdsa_generate_keypair (struct ecc_point *pub,
|
||||
struct ecc_scalar *key,
|
||||
void *random_ctx, nettle_random_func *random);
|
||||
|
||||
/* Low-level ECDSA functions. */
|
||||
mp_size_t
|
||||
ecc_ecdsa_sign_itch (const struct ecc_curve *ecc);
|
||||
|
||||
void
|
||||
ecc_ecdsa_sign (const struct ecc_curve *ecc,
|
||||
const mp_limb_t *zp,
|
||||
/* Random nonce, must be invertible mod ecc group
|
||||
order. */
|
||||
const mp_limb_t *kp,
|
||||
size_t length, const uint8_t *digest,
|
||||
mp_limb_t *rp, mp_limb_t *sp,
|
||||
mp_limb_t *scratch);
|
||||
|
||||
mp_size_t
|
||||
ecc_ecdsa_verify_itch (const struct ecc_curve *ecc);
|
||||
|
||||
int
|
||||
ecc_ecdsa_verify (const struct ecc_curve *ecc,
|
||||
const mp_limb_t *pp, /* Public key */
|
||||
size_t length, const uint8_t *digest,
|
||||
const mp_limb_t *rp, const mp_limb_t *sp,
|
||||
mp_limb_t *scratch);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* NETTLE_ECDSA_H_INCLUDED */
|
||||
@@ -1,149 +0,0 @@
|
||||
/* eddsa.h
|
||||
|
||||
Copyright (C) 2014 Niels Möller
|
||||
|
||||
This file is part of GNU Nettle.
|
||||
|
||||
GNU Nettle is free software: you can redistribute it and/or
|
||||
modify it under the terms of either:
|
||||
|
||||
* the GNU Lesser General Public License as published by the Free
|
||||
Software Foundation; either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or
|
||||
|
||||
* the GNU General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or both in parallel, as here.
|
||||
|
||||
GNU Nettle is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received copies of the GNU General Public License and
|
||||
the GNU Lesser General Public License along with this program. If
|
||||
not, see http://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
#ifndef NETTLE_EDDSA_H
|
||||
#define NETTLE_EDDSA_H
|
||||
|
||||
#include "nettle-types.h"
|
||||
|
||||
#include "bignum.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Name mangling */
|
||||
#define ed25519_sha512_set_private_key nettle_ed25519_sha512_set_private_key
|
||||
#define ed25519_sha512_public_key nettle_ed25519_sha512_public_key
|
||||
#define ed25519_sha512_sign nettle_ed25519_sha512_sign
|
||||
#define ed25519_sha512_verify nettle_ed25519_sha512_verify
|
||||
|
||||
#define _eddsa_compress _nettle_eddsa_compress
|
||||
#define _eddsa_compress_itch _nettle_eddsa_compress_itch
|
||||
#define _eddsa_decompress _nettle_eddsa_decompress
|
||||
#define _eddsa_decompress_itch _nettle_eddsa_decompress_itch
|
||||
#define _eddsa_hash _nettle_eddsa_hash
|
||||
#define _eddsa_expand_key _nettle_eddsa_expand_key
|
||||
#define _eddsa_sign _nettle_eddsa_sign
|
||||
#define _eddsa_sign_itch _nettle_eddsa_sign_itch
|
||||
#define _eddsa_verify _nettle_eddsa_verify
|
||||
#define _eddsa_verify_itch _nettle_eddsa_verify_itch
|
||||
#define _eddsa_public_key_itch _nettle_eddsa_public_key_itch
|
||||
#define _eddsa_public_key _nettle_eddsa_public_key
|
||||
|
||||
#define ED25519_KEY_SIZE 32
|
||||
#define ED25519_SIGNATURE_SIZE 64
|
||||
|
||||
void
|
||||
ed25519_sha512_public_key (uint8_t *pub, const uint8_t *priv);
|
||||
|
||||
void
|
||||
ed25519_sha512_sign (const uint8_t *pub,
|
||||
const uint8_t *priv,
|
||||
size_t length, const uint8_t *msg,
|
||||
uint8_t *signature);
|
||||
|
||||
int
|
||||
ed25519_sha512_verify (const uint8_t *pub,
|
||||
size_t length, const uint8_t *msg,
|
||||
const uint8_t *signature);
|
||||
|
||||
/* Low-level internal functions */
|
||||
|
||||
struct ecc_curve;
|
||||
struct ecc_modulo;
|
||||
|
||||
mp_size_t
|
||||
_eddsa_compress_itch (const struct ecc_curve *ecc);
|
||||
void
|
||||
_eddsa_compress (const struct ecc_curve *ecc, uint8_t *r, mp_limb_t *p,
|
||||
mp_limb_t *scratch);
|
||||
|
||||
mp_size_t
|
||||
_eddsa_decompress_itch (const struct ecc_curve *ecc);
|
||||
int
|
||||
_eddsa_decompress (const struct ecc_curve *ecc, mp_limb_t *p,
|
||||
const uint8_t *cp,
|
||||
mp_limb_t *scratch);
|
||||
|
||||
void
|
||||
_eddsa_hash (const struct ecc_modulo *m,
|
||||
mp_limb_t *rp, const uint8_t *digest);
|
||||
|
||||
mp_size_t
|
||||
_eddsa_sign_itch (const struct ecc_curve *ecc);
|
||||
|
||||
void
|
||||
_eddsa_sign (const struct ecc_curve *ecc,
|
||||
const struct nettle_hash *H,
|
||||
const uint8_t *pub,
|
||||
void *ctx,
|
||||
const mp_limb_t *k2,
|
||||
size_t length,
|
||||
const uint8_t *msg,
|
||||
uint8_t *signature,
|
||||
mp_limb_t *scratch);
|
||||
|
||||
mp_size_t
|
||||
_eddsa_verify_itch (const struct ecc_curve *ecc);
|
||||
|
||||
int
|
||||
_eddsa_verify (const struct ecc_curve *ecc,
|
||||
const struct nettle_hash *H,
|
||||
const uint8_t *pub,
|
||||
const mp_limb_t *A,
|
||||
void *ctx,
|
||||
size_t length,
|
||||
const uint8_t *msg,
|
||||
const uint8_t *signature,
|
||||
mp_limb_t *scratch);
|
||||
|
||||
void
|
||||
_eddsa_expand_key (const struct ecc_curve *ecc,
|
||||
const struct nettle_hash *H,
|
||||
void *ctx,
|
||||
const uint8_t *key,
|
||||
uint8_t *digest,
|
||||
mp_limb_t *k2);
|
||||
|
||||
mp_size_t
|
||||
_eddsa_public_key_itch (const struct ecc_curve *ecc);
|
||||
|
||||
void
|
||||
_eddsa_public_key (const struct ecc_curve *ecc,
|
||||
const mp_limb_t *k, uint8_t *pub, mp_limb_t *scratch);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* NETTLE_EDDSA_H */
|
||||
@@ -1,327 +0,0 @@
|
||||
/* gcm.h
|
||||
|
||||
Galois counter mode, specified by NIST,
|
||||
http://csrc.nist.gov/publications/nistpubs/800-38D/SP-800-38D.pdf
|
||||
|
||||
Copyright (C) 2011 Katholieke Universiteit Leuven
|
||||
Copyright (C) 2011, 2014 Niels Möller
|
||||
|
||||
Contributed by Nikos Mavrogiannopoulos
|
||||
|
||||
This file is part of GNU Nettle.
|
||||
|
||||
GNU Nettle is free software: you can redistribute it and/or
|
||||
modify it under the terms of either:
|
||||
|
||||
* the GNU Lesser General Public License as published by the Free
|
||||
Software Foundation; either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or
|
||||
|
||||
* the GNU General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or both in parallel, as here.
|
||||
|
||||
GNU Nettle is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received copies of the GNU General Public License and
|
||||
the GNU Lesser General Public License along with this program. If
|
||||
not, see http://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
#ifndef NETTLE_GCM_H_INCLUDED
|
||||
#define NETTLE_GCM_H_INCLUDED
|
||||
|
||||
#include "aes.h"
|
||||
#include "camellia.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Name mangling */
|
||||
#define gcm_set_key nettle_gcm_set_key
|
||||
#define gcm_set_iv nettle_gcm_set_iv
|
||||
#define gcm_update nettle_gcm_update
|
||||
#define gcm_encrypt nettle_gcm_encrypt
|
||||
#define gcm_decrypt nettle_gcm_decrypt
|
||||
#define gcm_digest nettle_gcm_digest
|
||||
|
||||
#define gcm_aes128_set_key nettle_gcm_aes128_set_key
|
||||
#define gcm_aes128_set_iv nettle_gcm_aes128_set_iv
|
||||
#define gcm_aes128_update nettle_gcm_aes128_update
|
||||
#define gcm_aes128_encrypt nettle_gcm_aes128_encrypt
|
||||
#define gcm_aes128_decrypt nettle_gcm_aes128_decrypt
|
||||
#define gcm_aes128_digest nettle_gcm_aes128_digest
|
||||
|
||||
#define gcm_aes192_set_key nettle_gcm_aes192_set_key
|
||||
#define gcm_aes192_set_iv nettle_gcm_aes192_set_iv
|
||||
#define gcm_aes192_update nettle_gcm_aes192_update
|
||||
#define gcm_aes192_encrypt nettle_gcm_aes192_encrypt
|
||||
#define gcm_aes192_decrypt nettle_gcm_aes192_decrypt
|
||||
#define gcm_aes192_digest nettle_gcm_aes192_digest
|
||||
|
||||
#define gcm_aes256_set_key nettle_gcm_aes256_set_key
|
||||
#define gcm_aes256_set_iv nettle_gcm_aes256_set_iv
|
||||
#define gcm_aes256_update nettle_gcm_aes256_update
|
||||
#define gcm_aes256_encrypt nettle_gcm_aes256_encrypt
|
||||
#define gcm_aes256_decrypt nettle_gcm_aes256_decrypt
|
||||
#define gcm_aes256_digest nettle_gcm_aes256_digest
|
||||
|
||||
#define gcm_aes_set_key nettle_gcm_aes_set_key
|
||||
#define gcm_aes_set_iv nettle_gcm_aes_set_iv
|
||||
#define gcm_aes_update nettle_gcm_aes_update
|
||||
#define gcm_aes_encrypt nettle_gcm_aes_encrypt
|
||||
#define gcm_aes_decrypt nettle_gcm_aes_decrypt
|
||||
#define gcm_aes_digest nettle_gcm_aes_digest
|
||||
|
||||
#define gcm_camellia128_set_key nettle_gcm_camellia128_set_key
|
||||
#define gcm_camellia128_set_iv nettle_gcm_camellia128_set_iv
|
||||
#define gcm_camellia128_update nettle_gcm_camellia128_update
|
||||
#define gcm_camellia128_encrypt nettle_gcm_camellia128_encrypt
|
||||
#define gcm_camellia128_decrypt nettle_gcm_camellia128_decrypt
|
||||
#define gcm_camellia128_digest nettle_gcm_camellia128_digest
|
||||
|
||||
#define gcm_camellia256_set_key nettle_gcm_camellia256_set_key
|
||||
#define gcm_camellia256_set_iv nettle_gcm_camellia256_set_iv
|
||||
#define gcm_camellia256_update nettle_gcm_camellia256_update
|
||||
#define gcm_camellia256_encrypt nettle_gcm_camellia256_encrypt
|
||||
#define gcm_camellia256_decrypt nettle_gcm_camellia256_decrypt
|
||||
#define gcm_camellia256_digest nettle_gcm_camellia256_digest
|
||||
|
||||
#define GCM_BLOCK_SIZE 16
|
||||
#define GCM_IV_SIZE (GCM_BLOCK_SIZE - 4)
|
||||
#define GCM_DIGEST_SIZE 16
|
||||
#define GCM_TABLE_BITS 8
|
||||
|
||||
/* Hashing subkey */
|
||||
struct gcm_key
|
||||
{
|
||||
union nettle_block16 h[1 << GCM_TABLE_BITS];
|
||||
};
|
||||
|
||||
/* Per-message state, depending on the iv */
|
||||
struct gcm_ctx {
|
||||
/* Original counter block */
|
||||
union nettle_block16 iv;
|
||||
/* Updated for each block. */
|
||||
union nettle_block16 ctr;
|
||||
/* Hashing state */
|
||||
union nettle_block16 x;
|
||||
uint64_t auth_size;
|
||||
uint64_t data_size;
|
||||
};
|
||||
|
||||
void
|
||||
gcm_set_key(struct gcm_key *key,
|
||||
const void *cipher, nettle_cipher_func *f);
|
||||
|
||||
void
|
||||
gcm_set_iv(struct gcm_ctx *ctx, const struct gcm_key *key,
|
||||
size_t length, const uint8_t *iv);
|
||||
|
||||
void
|
||||
gcm_update(struct gcm_ctx *ctx, const struct gcm_key *key,
|
||||
size_t length, const uint8_t *data);
|
||||
|
||||
void
|
||||
gcm_encrypt(struct gcm_ctx *ctx, const struct gcm_key *key,
|
||||
const void *cipher, nettle_cipher_func *f,
|
||||
size_t length, uint8_t *dst, const uint8_t *src);
|
||||
|
||||
void
|
||||
gcm_decrypt(struct gcm_ctx *ctx, const struct gcm_key *key,
|
||||
const void *cipher, nettle_cipher_func *f,
|
||||
size_t length, uint8_t *dst, const uint8_t *src);
|
||||
|
||||
void
|
||||
gcm_digest(struct gcm_ctx *ctx, const struct gcm_key *key,
|
||||
const void *cipher, nettle_cipher_func *f,
|
||||
size_t length, uint8_t *digest);
|
||||
|
||||
/* Convenience macrology (not sure how useful it is) */
|
||||
/* All-in-one context, with hash subkey, message state, and cipher. */
|
||||
#define GCM_CTX(type) \
|
||||
{ struct gcm_key key; struct gcm_ctx gcm; type cipher; }
|
||||
|
||||
/* NOTE: Avoid using NULL, as we don't include anything defining it. */
|
||||
#define GCM_SET_KEY(ctx, set_key, encrypt, gcm_key) \
|
||||
do { \
|
||||
(set_key)(&(ctx)->cipher, (gcm_key)); \
|
||||
if (0) (encrypt)(&(ctx)->cipher, ~(size_t) 0, \
|
||||
(uint8_t *) 0, (const uint8_t *) 0); \
|
||||
gcm_set_key(&(ctx)->key, &(ctx)->cipher, \
|
||||
(nettle_cipher_func *) (encrypt)); \
|
||||
} while (0)
|
||||
|
||||
#define GCM_SET_IV(ctx, length, data) \
|
||||
gcm_set_iv(&(ctx)->gcm, &(ctx)->key, (length), (data))
|
||||
|
||||
#define GCM_UPDATE(ctx, length, data) \
|
||||
gcm_update(&(ctx)->gcm, &(ctx)->key, (length), (data))
|
||||
|
||||
#define GCM_ENCRYPT(ctx, encrypt, length, dst, src) \
|
||||
(0 ? (encrypt)(&(ctx)->cipher, ~(size_t) 0, \
|
||||
(uint8_t *) 0, (const uint8_t *) 0) \
|
||||
: gcm_encrypt(&(ctx)->gcm, &(ctx)->key, &(ctx)->cipher, \
|
||||
(nettle_cipher_func *) (encrypt), \
|
||||
(length), (dst), (src)))
|
||||
|
||||
#define GCM_DECRYPT(ctx, encrypt, length, dst, src) \
|
||||
(0 ? (encrypt)(&(ctx)->cipher, ~(size_t) 0, \
|
||||
(uint8_t *) 0, (const uint8_t *) 0) \
|
||||
: gcm_decrypt(&(ctx)->gcm, &(ctx)->key, &(ctx)->cipher, \
|
||||
(nettle_cipher_func *) (encrypt), \
|
||||
(length), (dst), (src)))
|
||||
|
||||
#define GCM_DIGEST(ctx, encrypt, length, digest) \
|
||||
(0 ? (encrypt)(&(ctx)->cipher, ~(size_t) 0, \
|
||||
(uint8_t *) 0, (const uint8_t *) 0) \
|
||||
: gcm_digest(&(ctx)->gcm, &(ctx)->key, &(ctx)->cipher, \
|
||||
(nettle_cipher_func *) (encrypt), \
|
||||
(length), (digest)))
|
||||
|
||||
struct gcm_aes128_ctx GCM_CTX(struct aes128_ctx);
|
||||
|
||||
void
|
||||
gcm_aes128_set_key(struct gcm_aes128_ctx *ctx, const uint8_t *key);
|
||||
|
||||
/* FIXME: Define _update and _set_iv as some kind of aliaes,
|
||||
there's nothing aes-specific. */
|
||||
void
|
||||
gcm_aes128_update (struct gcm_aes128_ctx *ctx,
|
||||
size_t length, const uint8_t *data);
|
||||
void
|
||||
gcm_aes128_set_iv (struct gcm_aes128_ctx *ctx,
|
||||
size_t length, const uint8_t *iv);
|
||||
|
||||
void
|
||||
gcm_aes128_encrypt(struct gcm_aes128_ctx *ctx,
|
||||
size_t length, uint8_t *dst, const uint8_t *src);
|
||||
|
||||
void
|
||||
gcm_aes128_decrypt(struct gcm_aes128_ctx *ctx,
|
||||
size_t length, uint8_t *dst, const uint8_t *src);
|
||||
|
||||
void
|
||||
gcm_aes128_digest(struct gcm_aes128_ctx *ctx,
|
||||
size_t length, uint8_t *digest);
|
||||
|
||||
struct gcm_aes192_ctx GCM_CTX(struct aes192_ctx);
|
||||
|
||||
void
|
||||
gcm_aes192_set_key(struct gcm_aes192_ctx *ctx, const uint8_t *key);
|
||||
|
||||
void
|
||||
gcm_aes192_update (struct gcm_aes192_ctx *ctx,
|
||||
size_t length, const uint8_t *data);
|
||||
void
|
||||
gcm_aes192_set_iv (struct gcm_aes192_ctx *ctx,
|
||||
size_t length, const uint8_t *iv);
|
||||
|
||||
void
|
||||
gcm_aes192_encrypt(struct gcm_aes192_ctx *ctx,
|
||||
size_t length, uint8_t *dst, const uint8_t *src);
|
||||
|
||||
void
|
||||
gcm_aes192_decrypt(struct gcm_aes192_ctx *ctx,
|
||||
size_t length, uint8_t *dst, const uint8_t *src);
|
||||
|
||||
void
|
||||
gcm_aes192_digest(struct gcm_aes192_ctx *ctx,
|
||||
size_t length, uint8_t *digest);
|
||||
|
||||
struct gcm_aes256_ctx GCM_CTX(struct aes256_ctx);
|
||||
|
||||
void
|
||||
gcm_aes256_set_key(struct gcm_aes256_ctx *ctx, const uint8_t *key);
|
||||
|
||||
void
|
||||
gcm_aes256_update (struct gcm_aes256_ctx *ctx,
|
||||
size_t length, const uint8_t *data);
|
||||
void
|
||||
gcm_aes256_set_iv (struct gcm_aes256_ctx *ctx,
|
||||
size_t length, const uint8_t *iv);
|
||||
|
||||
void
|
||||
gcm_aes256_encrypt(struct gcm_aes256_ctx *ctx,
|
||||
size_t length, uint8_t *dst, const uint8_t *src);
|
||||
|
||||
void
|
||||
gcm_aes256_decrypt(struct gcm_aes256_ctx *ctx,
|
||||
size_t length, uint8_t *dst, const uint8_t *src);
|
||||
|
||||
void
|
||||
gcm_aes256_digest(struct gcm_aes256_ctx *ctx,
|
||||
size_t length, uint8_t *digest);
|
||||
|
||||
/* Old aes interface, for backwards compatibility */
|
||||
struct gcm_aes_ctx GCM_CTX(struct aes_ctx);
|
||||
|
||||
void
|
||||
gcm_aes_set_key(struct gcm_aes_ctx *ctx,
|
||||
size_t length, const uint8_t *key);
|
||||
|
||||
void
|
||||
gcm_aes_set_iv(struct gcm_aes_ctx *ctx,
|
||||
size_t length, const uint8_t *iv);
|
||||
|
||||
void
|
||||
gcm_aes_update(struct gcm_aes_ctx *ctx,
|
||||
size_t length, const uint8_t *data);
|
||||
|
||||
void
|
||||
gcm_aes_encrypt(struct gcm_aes_ctx *ctx,
|
||||
size_t length, uint8_t *dst, const uint8_t *src);
|
||||
|
||||
void
|
||||
gcm_aes_decrypt(struct gcm_aes_ctx *ctx,
|
||||
size_t length, uint8_t *dst, const uint8_t *src);
|
||||
|
||||
void
|
||||
gcm_aes_digest(struct gcm_aes_ctx *ctx, size_t length, uint8_t *digest);
|
||||
|
||||
|
||||
struct gcm_camellia128_ctx GCM_CTX(struct camellia128_ctx);
|
||||
|
||||
void gcm_camellia128_set_key(struct gcm_camellia128_ctx *ctx,
|
||||
const uint8_t *key);
|
||||
void gcm_camellia128_set_iv(struct gcm_camellia128_ctx *ctx,
|
||||
size_t length, const uint8_t *iv);
|
||||
void gcm_camellia128_update(struct gcm_camellia128_ctx *ctx,
|
||||
size_t length, const uint8_t *data);
|
||||
void gcm_camellia128_encrypt(struct gcm_camellia128_ctx *ctx,
|
||||
size_t length, uint8_t *dst, const uint8_t *src);
|
||||
void gcm_camellia128_decrypt(struct gcm_camellia128_ctx *ctx,
|
||||
size_t length, uint8_t *dst, const uint8_t *src);
|
||||
void gcm_camellia128_digest(struct gcm_camellia128_ctx *ctx,
|
||||
size_t length, uint8_t *digest);
|
||||
|
||||
|
||||
struct gcm_camellia256_ctx GCM_CTX(struct camellia256_ctx);
|
||||
|
||||
void gcm_camellia256_set_key(struct gcm_camellia256_ctx *ctx,
|
||||
const uint8_t *key);
|
||||
void gcm_camellia256_set_iv(struct gcm_camellia256_ctx *ctx,
|
||||
size_t length, const uint8_t *iv);
|
||||
void gcm_camellia256_update(struct gcm_camellia256_ctx *ctx,
|
||||
size_t length, const uint8_t *data);
|
||||
void gcm_camellia256_encrypt(struct gcm_camellia256_ctx *ctx,
|
||||
size_t length, uint8_t *dst, const uint8_t *src);
|
||||
void gcm_camellia256_decrypt(struct gcm_camellia256_ctx *ctx,
|
||||
size_t length, uint8_t *dst, const uint8_t *src);
|
||||
void gcm_camellia256_digest(struct gcm_camellia256_ctx *ctx,
|
||||
size_t length, uint8_t *digest);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* NETTLE_GCM_H_INCLUDED */
|
||||
@@ -1,98 +0,0 @@
|
||||
/* gosthash94.h
|
||||
|
||||
The GOST R 34.11-94 hash function, described in RFC 5831.
|
||||
|
||||
Copyright (C) 2012 Nikos Mavrogiannopoulos, Niels Möller
|
||||
|
||||
This file is part of GNU Nettle.
|
||||
|
||||
GNU Nettle is free software: you can redistribute it and/or
|
||||
modify it under the terms of either:
|
||||
|
||||
* the GNU Lesser General Public License as published by the Free
|
||||
Software Foundation; either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or
|
||||
|
||||
* the GNU General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or both in parallel, as here.
|
||||
|
||||
GNU Nettle is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received copies of the GNU General Public License and
|
||||
the GNU Lesser General Public License along with this program. If
|
||||
not, see http://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
/* Based on rhash gost.h. */
|
||||
|
||||
/* Copyright: 2009-2012 Aleksey Kravchenko <rhash.admin@gmail.com>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included
|
||||
* in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Ported to nettle by Nikos Mavrogiannopoulos.
|
||||
*/
|
||||
|
||||
#ifndef NETTLE_GOSTHASH94_H_INCLUDED
|
||||
#define NETTLE_GOSTHASH94_H_INCLUDED
|
||||
|
||||
#include "nettle-types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define gosthash94_init nettle_gosthash94_init
|
||||
#define gosthash94_update nettle_gosthash94_update
|
||||
#define gosthash94_digest nettle_gosthash94_digest
|
||||
|
||||
#define GOSTHASH94_BLOCK_SIZE 32
|
||||
#define GOSTHASH94_DIGEST_SIZE 32
|
||||
/* For backwards compatibility */
|
||||
#define GOSTHASH94_DATA_SIZE GOSTHASH94_BLOCK_SIZE
|
||||
|
||||
struct gosthash94_ctx
|
||||
{
|
||||
uint32_t hash[8]; /* algorithm 256-bit state */
|
||||
uint32_t sum[8]; /* sum of processed message blocks */
|
||||
uint8_t message[GOSTHASH94_BLOCK_SIZE]; /* 256-bit buffer for leftovers */
|
||||
uint64_t length; /* number of processed bytes */
|
||||
};
|
||||
|
||||
void gosthash94_init(struct gosthash94_ctx *ctx);
|
||||
void gosthash94_update(struct gosthash94_ctx *ctx,
|
||||
size_t length, const uint8_t *msg);
|
||||
void gosthash94_digest(struct gosthash94_ctx *ctx,
|
||||
size_t length, uint8_t *result);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* NETTLE_GOSTHASH94_H_INCLUDED */
|
||||
@@ -1,67 +0,0 @@
|
||||
/* hkdf.h
|
||||
|
||||
TLS PRF code (RFC-5246, RFC-2246).
|
||||
|
||||
Copyright (C) 2017 Red Hat, Inc.
|
||||
|
||||
This file is part of GNU Nettle.
|
||||
|
||||
GNU Nettle is free software: you can redistribute it and/or
|
||||
modify it under the terms of either:
|
||||
|
||||
* the GNU Lesser General Public License as published by the Free
|
||||
Software Foundation; either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or
|
||||
|
||||
* the GNU General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or both in parallel, as here.
|
||||
|
||||
GNU Nettle is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received copies of the GNU General Public License and
|
||||
the GNU Lesser General Public License along with this program. If
|
||||
not, see http://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
#ifndef NETTLE_HKDF_H_INCLUDED
|
||||
#define NETTLE_HKDF_H_INCLUDED
|
||||
|
||||
#include "nettle-types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Namespace mangling */
|
||||
#define hkdf_extract nettle_hkdf_extract
|
||||
#define hkdf_expand nettle_hkdf_expand
|
||||
|
||||
void
|
||||
hkdf_extract(void *mac_ctx,
|
||||
nettle_hash_update_func *update,
|
||||
nettle_hash_digest_func *digest,
|
||||
size_t digest_size,
|
||||
size_t secret_size, const uint8_t *secret,
|
||||
uint8_t *dst);
|
||||
|
||||
void
|
||||
hkdf_expand(void *mac_ctx,
|
||||
nettle_hash_update_func *update,
|
||||
nettle_hash_digest_func *digest,
|
||||
size_t digest_size,
|
||||
size_t info_size, const uint8_t *info,
|
||||
size_t length, uint8_t *dst);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* NETTLE_HKDF_H_INCLUDED */
|
||||
@@ -1,210 +0,0 @@
|
||||
/* hmac.h
|
||||
|
||||
HMAC message authentication code (RFC-2104).
|
||||
|
||||
Copyright (C) 2001, 2002 Niels Möller
|
||||
|
||||
This file is part of GNU Nettle.
|
||||
|
||||
GNU Nettle is free software: you can redistribute it and/or
|
||||
modify it under the terms of either:
|
||||
|
||||
* the GNU Lesser General Public License as published by the Free
|
||||
Software Foundation; either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or
|
||||
|
||||
* the GNU General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or both in parallel, as here.
|
||||
|
||||
GNU Nettle is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received copies of the GNU General Public License and
|
||||
the GNU Lesser General Public License along with this program. If
|
||||
not, see http://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
#ifndef NETTLE_HMAC_H_INCLUDED
|
||||
#define NETTLE_HMAC_H_INCLUDED
|
||||
|
||||
#include "nettle-meta.h"
|
||||
|
||||
#include "md5.h"
|
||||
#include "ripemd160.h"
|
||||
#include "sha1.h"
|
||||
#include "sha2.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Namespace mangling */
|
||||
#define hmac_set_key nettle_hmac_set_key
|
||||
#define hmac_update nettle_hmac_update
|
||||
#define hmac_digest nettle_hmac_digest
|
||||
#define hmac_md5_set_key nettle_hmac_md5_set_key
|
||||
#define hmac_md5_update nettle_hmac_md5_update
|
||||
#define hmac_md5_digest nettle_hmac_md5_digest
|
||||
#define hmac_ripemd160_set_key nettle_hmac_ripemd160_set_key
|
||||
#define hmac_ripemd160_update nettle_hmac_ripemd160_update
|
||||
#define hmac_ripemd160_digest nettle_hmac_ripemd160_digest
|
||||
#define hmac_sha1_set_key nettle_hmac_sha1_set_key
|
||||
#define hmac_sha1_update nettle_hmac_sha1_update
|
||||
#define hmac_sha1_digest nettle_hmac_sha1_digest
|
||||
#define hmac_sha224_set_key nettle_hmac_sha224_set_key
|
||||
#define hmac_sha224_digest nettle_hmac_sha224_digest
|
||||
#define hmac_sha256_set_key nettle_hmac_sha256_set_key
|
||||
#define hmac_sha256_update nettle_hmac_sha256_update
|
||||
#define hmac_sha256_digest nettle_hmac_sha256_digest
|
||||
#define hmac_sha384_set_key nettle_hmac_sha384_set_key
|
||||
#define hmac_sha384_digest nettle_hmac_sha384_digest
|
||||
#define hmac_sha512_set_key nettle_hmac_sha512_set_key
|
||||
#define hmac_sha512_update nettle_hmac_sha512_update
|
||||
#define hmac_sha512_digest nettle_hmac_sha512_digest
|
||||
|
||||
void
|
||||
hmac_set_key(void *outer, void *inner, void *state,
|
||||
const struct nettle_hash *hash,
|
||||
size_t length, const uint8_t *key);
|
||||
|
||||
/* This function is not strictly needed, it's s just the same as the
|
||||
* hash update function. */
|
||||
void
|
||||
hmac_update(void *state,
|
||||
const struct nettle_hash *hash,
|
||||
size_t length, const uint8_t *data);
|
||||
|
||||
void
|
||||
hmac_digest(const void *outer, const void *inner, void *state,
|
||||
const struct nettle_hash *hash,
|
||||
size_t length, uint8_t *digest);
|
||||
|
||||
|
||||
#define HMAC_CTX(type) \
|
||||
{ type outer; type inner; type state; }
|
||||
|
||||
#define HMAC_SET_KEY(ctx, hash, length, key) \
|
||||
hmac_set_key( &(ctx)->outer, &(ctx)->inner, &(ctx)->state, \
|
||||
(hash), (length), (key) )
|
||||
|
||||
#define HMAC_DIGEST(ctx, hash, length, digest) \
|
||||
hmac_digest( &(ctx)->outer, &(ctx)->inner, &(ctx)->state, \
|
||||
(hash), (length), (digest) )
|
||||
|
||||
/* HMAC using specific hash functions */
|
||||
|
||||
/* hmac-md5 */
|
||||
struct hmac_md5_ctx HMAC_CTX(struct md5_ctx);
|
||||
|
||||
void
|
||||
hmac_md5_set_key(struct hmac_md5_ctx *ctx,
|
||||
size_t key_length, const uint8_t *key);
|
||||
|
||||
void
|
||||
hmac_md5_update(struct hmac_md5_ctx *ctx,
|
||||
size_t length, const uint8_t *data);
|
||||
|
||||
void
|
||||
hmac_md5_digest(struct hmac_md5_ctx *ctx,
|
||||
size_t length, uint8_t *digest);
|
||||
|
||||
|
||||
/* hmac-ripemd160 */
|
||||
struct hmac_ripemd160_ctx HMAC_CTX(struct ripemd160_ctx);
|
||||
|
||||
void
|
||||
hmac_ripemd160_set_key(struct hmac_ripemd160_ctx *ctx,
|
||||
size_t key_length, const uint8_t *key);
|
||||
|
||||
void
|
||||
hmac_ripemd160_update(struct hmac_ripemd160_ctx *ctx,
|
||||
size_t length, const uint8_t *data);
|
||||
|
||||
void
|
||||
hmac_ripemd160_digest(struct hmac_ripemd160_ctx *ctx,
|
||||
size_t length, uint8_t *digest);
|
||||
|
||||
|
||||
/* hmac-sha1 */
|
||||
struct hmac_sha1_ctx HMAC_CTX(struct sha1_ctx);
|
||||
|
||||
void
|
||||
hmac_sha1_set_key(struct hmac_sha1_ctx *ctx,
|
||||
size_t key_length, const uint8_t *key);
|
||||
|
||||
void
|
||||
hmac_sha1_update(struct hmac_sha1_ctx *ctx,
|
||||
size_t length, const uint8_t *data);
|
||||
|
||||
void
|
||||
hmac_sha1_digest(struct hmac_sha1_ctx *ctx,
|
||||
size_t length, uint8_t *digest);
|
||||
|
||||
/* hmac-sha256 */
|
||||
struct hmac_sha256_ctx HMAC_CTX(struct sha256_ctx);
|
||||
|
||||
void
|
||||
hmac_sha256_set_key(struct hmac_sha256_ctx *ctx,
|
||||
size_t key_length, const uint8_t *key);
|
||||
|
||||
void
|
||||
hmac_sha256_update(struct hmac_sha256_ctx *ctx,
|
||||
size_t length, const uint8_t *data);
|
||||
|
||||
void
|
||||
hmac_sha256_digest(struct hmac_sha256_ctx *ctx,
|
||||
size_t length, uint8_t *digest);
|
||||
|
||||
/* hmac-sha224 */
|
||||
#define hmac_sha224_ctx hmac_sha256_ctx
|
||||
|
||||
void
|
||||
hmac_sha224_set_key(struct hmac_sha224_ctx *ctx,
|
||||
size_t key_length, const uint8_t *key);
|
||||
|
||||
#define hmac_sha224_update nettle_hmac_sha256_update
|
||||
|
||||
void
|
||||
hmac_sha224_digest(struct hmac_sha224_ctx *ctx,
|
||||
size_t length, uint8_t *digest);
|
||||
|
||||
/* hmac-sha512 */
|
||||
struct hmac_sha512_ctx HMAC_CTX(struct sha512_ctx);
|
||||
|
||||
void
|
||||
hmac_sha512_set_key(struct hmac_sha512_ctx *ctx,
|
||||
size_t key_length, const uint8_t *key);
|
||||
|
||||
void
|
||||
hmac_sha512_update(struct hmac_sha512_ctx *ctx,
|
||||
size_t length, const uint8_t *data);
|
||||
|
||||
void
|
||||
hmac_sha512_digest(struct hmac_sha512_ctx *ctx,
|
||||
size_t length, uint8_t *digest);
|
||||
|
||||
/* hmac-sha384 */
|
||||
#define hmac_sha384_ctx hmac_sha512_ctx
|
||||
|
||||
void
|
||||
hmac_sha384_set_key(struct hmac_sha512_ctx *ctx,
|
||||
size_t key_length, const uint8_t *key);
|
||||
|
||||
#define hmac_sha384_update nettle_hmac_sha512_update
|
||||
|
||||
void
|
||||
hmac_sha384_digest(struct hmac_sha512_ctx *ctx,
|
||||
size_t length, uint8_t *digest);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* NETTLE_HMAC_H_INCLUDED */
|
||||
@@ -1,80 +0,0 @@
|
||||
/* knuth-lfib.h
|
||||
|
||||
The "lagged fibonacci" pseudorandomness generator, described in
|
||||
Knuth, TAoCP, 3.6
|
||||
|
||||
This file is part of GNU Nettle.
|
||||
|
||||
GNU Nettle is free software: you can redistribute it and/or
|
||||
modify it under the terms of either:
|
||||
|
||||
* the GNU Lesser General Public License as published by the Free
|
||||
Software Foundation; either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or
|
||||
|
||||
* the GNU General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or both in parallel, as here.
|
||||
|
||||
GNU Nettle is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received copies of the GNU General Public License and
|
||||
the GNU Lesser General Public License along with this program. If
|
||||
not, see http://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
/* NOTE: This generator is totally inappropriate for cryptographic
|
||||
* applications. It is useful for generating deterministic but
|
||||
* random-looking test data, and is used by the Nettle testsuite. */
|
||||
#ifndef NETTLE_KNUTH_LFIB_H_INCLUDED
|
||||
#define NETTLE_KNUTH_LFIB_H_INCLUDED
|
||||
|
||||
#include "nettle-types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Namespace mangling */
|
||||
#define knuth_lfib_init nettle_knuth_lfib_init
|
||||
#define knuth_lfib_get nettle_knuth_lfib_get
|
||||
#define knuth_lfib_get_array nettle_knuth_lfib_get_array
|
||||
#define knuth_lfib_random nettle_knuth_lfib_random
|
||||
|
||||
#define _KNUTH_LFIB_KK 100
|
||||
|
||||
struct knuth_lfib_ctx
|
||||
{
|
||||
uint32_t x[_KNUTH_LFIB_KK];
|
||||
unsigned index;
|
||||
};
|
||||
|
||||
void
|
||||
knuth_lfib_init(struct knuth_lfib_ctx *ctx, uint32_t seed);
|
||||
|
||||
/* Get's a single number in the range 0 ... 2^30-1 */
|
||||
uint32_t
|
||||
knuth_lfib_get(struct knuth_lfib_ctx *ctx);
|
||||
|
||||
/* Get an array of numbers */
|
||||
void
|
||||
knuth_lfib_get_array(struct knuth_lfib_ctx *ctx,
|
||||
size_t n, uint32_t *a);
|
||||
|
||||
/* Get an array of octets. */
|
||||
void
|
||||
knuth_lfib_random(struct knuth_lfib_ctx *ctx,
|
||||
size_t n, uint8_t *dst);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* NETTLE_KNUTH_LFIB_H_INCLUDED */
|
||||
@@ -1,245 +0,0 @@
|
||||
/* macros.h
|
||||
|
||||
Copyright (C) 2001, 2010 Niels Möller
|
||||
|
||||
This file is part of GNU Nettle.
|
||||
|
||||
GNU Nettle is free software: you can redistribute it and/or
|
||||
modify it under the terms of either:
|
||||
|
||||
* the GNU Lesser General Public License as published by the Free
|
||||
Software Foundation; either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or
|
||||
|
||||
* the GNU General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or both in parallel, as here.
|
||||
|
||||
GNU Nettle is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received copies of the GNU General Public License and
|
||||
the GNU Lesser General Public License along with this program. If
|
||||
not, see http://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
#ifndef NETTLE_MACROS_H_INCLUDED
|
||||
#define NETTLE_MACROS_H_INCLUDED
|
||||
|
||||
/* Reads a 64-bit integer, in network, big-endian, byte order */
|
||||
#define READ_UINT64(p) \
|
||||
( (((uint64_t) (p)[0]) << 56) \
|
||||
| (((uint64_t) (p)[1]) << 48) \
|
||||
| (((uint64_t) (p)[2]) << 40) \
|
||||
| (((uint64_t) (p)[3]) << 32) \
|
||||
| (((uint64_t) (p)[4]) << 24) \
|
||||
| (((uint64_t) (p)[5]) << 16) \
|
||||
| (((uint64_t) (p)[6]) << 8) \
|
||||
| ((uint64_t) (p)[7]))
|
||||
|
||||
#define WRITE_UINT64(p, i) \
|
||||
do { \
|
||||
(p)[0] = ((i) >> 56) & 0xff; \
|
||||
(p)[1] = ((i) >> 48) & 0xff; \
|
||||
(p)[2] = ((i) >> 40) & 0xff; \
|
||||
(p)[3] = ((i) >> 32) & 0xff; \
|
||||
(p)[4] = ((i) >> 24) & 0xff; \
|
||||
(p)[5] = ((i) >> 16) & 0xff; \
|
||||
(p)[6] = ((i) >> 8) & 0xff; \
|
||||
(p)[7] = (i) & 0xff; \
|
||||
} while(0)
|
||||
|
||||
/* Reads a 32-bit integer, in network, big-endian, byte order */
|
||||
#define READ_UINT32(p) \
|
||||
( (((uint32_t) (p)[0]) << 24) \
|
||||
| (((uint32_t) (p)[1]) << 16) \
|
||||
| (((uint32_t) (p)[2]) << 8) \
|
||||
| ((uint32_t) (p)[3]))
|
||||
|
||||
#define WRITE_UINT32(p, i) \
|
||||
do { \
|
||||
(p)[0] = ((i) >> 24) & 0xff; \
|
||||
(p)[1] = ((i) >> 16) & 0xff; \
|
||||
(p)[2] = ((i) >> 8) & 0xff; \
|
||||
(p)[3] = (i) & 0xff; \
|
||||
} while(0)
|
||||
|
||||
/* Analogous macros, for 24 and 16 bit numbers */
|
||||
#define READ_UINT24(p) \
|
||||
( (((uint32_t) (p)[0]) << 16) \
|
||||
| (((uint32_t) (p)[1]) << 8) \
|
||||
| ((uint32_t) (p)[2]))
|
||||
|
||||
#define WRITE_UINT24(p, i) \
|
||||
do { \
|
||||
(p)[0] = ((i) >> 16) & 0xff; \
|
||||
(p)[1] = ((i) >> 8) & 0xff; \
|
||||
(p)[2] = (i) & 0xff; \
|
||||
} while(0)
|
||||
|
||||
#define READ_UINT16(p) \
|
||||
( (((uint32_t) (p)[0]) << 8) \
|
||||
| ((uint32_t) (p)[1]))
|
||||
|
||||
#define WRITE_UINT16(p, i) \
|
||||
do { \
|
||||
(p)[0] = ((i) >> 8) & 0xff; \
|
||||
(p)[1] = (i) & 0xff; \
|
||||
} while(0)
|
||||
|
||||
/* And the other, little-endian, byteorder */
|
||||
#define LE_READ_UINT64(p) \
|
||||
( (((uint64_t) (p)[7]) << 56) \
|
||||
| (((uint64_t) (p)[6]) << 48) \
|
||||
| (((uint64_t) (p)[5]) << 40) \
|
||||
| (((uint64_t) (p)[4]) << 32) \
|
||||
| (((uint64_t) (p)[3]) << 24) \
|
||||
| (((uint64_t) (p)[2]) << 16) \
|
||||
| (((uint64_t) (p)[1]) << 8) \
|
||||
| ((uint64_t) (p)[0]))
|
||||
|
||||
#define LE_WRITE_UINT64(p, i) \
|
||||
do { \
|
||||
(p)[7] = ((i) >> 56) & 0xff; \
|
||||
(p)[6] = ((i) >> 48) & 0xff; \
|
||||
(p)[5] = ((i) >> 40) & 0xff; \
|
||||
(p)[4] = ((i) >> 32) & 0xff; \
|
||||
(p)[3] = ((i) >> 24) & 0xff; \
|
||||
(p)[2] = ((i) >> 16) & 0xff; \
|
||||
(p)[1] = ((i) >> 8) & 0xff; \
|
||||
(p)[0] = (i) & 0xff; \
|
||||
} while (0)
|
||||
|
||||
#define LE_READ_UINT32(p) \
|
||||
( (((uint32_t) (p)[3]) << 24) \
|
||||
| (((uint32_t) (p)[2]) << 16) \
|
||||
| (((uint32_t) (p)[1]) << 8) \
|
||||
| ((uint32_t) (p)[0]))
|
||||
|
||||
#define LE_WRITE_UINT32(p, i) \
|
||||
do { \
|
||||
(p)[3] = ((i) >> 24) & 0xff; \
|
||||
(p)[2] = ((i) >> 16) & 0xff; \
|
||||
(p)[1] = ((i) >> 8) & 0xff; \
|
||||
(p)[0] = (i) & 0xff; \
|
||||
} while(0)
|
||||
|
||||
/* Analogous macros, for 16 bit numbers */
|
||||
#define LE_READ_UINT16(p) \
|
||||
( (((uint32_t) (p)[1]) << 8) \
|
||||
| ((uint32_t) (p)[0]))
|
||||
|
||||
#define LE_WRITE_UINT16(p, i) \
|
||||
do { \
|
||||
(p)[1] = ((i) >> 8) & 0xff; \
|
||||
(p)[0] = (i) & 0xff; \
|
||||
} while(0)
|
||||
|
||||
/* Macro to make it easier to loop over several blocks. */
|
||||
#define FOR_BLOCKS(length, dst, src, blocksize) \
|
||||
assert( !((length) % (blocksize))); \
|
||||
for (; (length); ((length) -= (blocksize), \
|
||||
(dst) += (blocksize), \
|
||||
(src) += (blocksize)) )
|
||||
|
||||
/* The masking of the right shift is needed to allow n == 0 (using
|
||||
just 32 - n and 64 - n results in undefined behaviour). Most uses
|
||||
of these macros use a constant and non-zero rotation count. */
|
||||
#define ROTL32(n,x) (((x)<<(n)) | ((x)>>((-(n)&31))))
|
||||
|
||||
#define ROTL64(n,x) (((x)<<(n)) | ((x)>>((-(n))&63)))
|
||||
|
||||
/* Requires that size > 0 */
|
||||
#define INCREMENT(size, ctr) \
|
||||
do { \
|
||||
unsigned increment_i = (size) - 1; \
|
||||
if (++(ctr)[increment_i] == 0) \
|
||||
while (increment_i > 0 \
|
||||
&& ++(ctr)[--increment_i] == 0 ) \
|
||||
; \
|
||||
} while (0)
|
||||
|
||||
|
||||
/* Helper macro for Merkle-Damgård hash functions. Assumes the context
|
||||
structs includes the following fields:
|
||||
|
||||
uint8_t block[...]; // Buffer holding one block
|
||||
unsigned int index; // Index into block
|
||||
*/
|
||||
|
||||
/* Currently used by sha512 (and sha384) only. */
|
||||
#define MD_INCR(ctx) ((ctx)->count_high += !++(ctx)->count_low)
|
||||
|
||||
/* Takes the compression function f as argument. NOTE: also clobbers
|
||||
length and data. */
|
||||
#define MD_UPDATE(ctx, length, data, f, incr) \
|
||||
do { \
|
||||
if ((ctx)->index) \
|
||||
{ \
|
||||
/* Try to fill partial block */ \
|
||||
unsigned __md_left = sizeof((ctx)->block) - (ctx)->index; \
|
||||
if ((length) < __md_left) \
|
||||
{ \
|
||||
memcpy((ctx)->block + (ctx)->index, (data), (length)); \
|
||||
(ctx)->index += (length); \
|
||||
goto __md_done; /* Finished */ \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
memcpy((ctx)->block + (ctx)->index, (data), __md_left); \
|
||||
\
|
||||
f((ctx), (ctx)->block); \
|
||||
(incr); \
|
||||
\
|
||||
(data) += __md_left; \
|
||||
(length) -= __md_left; \
|
||||
} \
|
||||
} \
|
||||
while ((length) >= sizeof((ctx)->block)) \
|
||||
{ \
|
||||
f((ctx), (data)); \
|
||||
(incr); \
|
||||
\
|
||||
(data) += sizeof((ctx)->block); \
|
||||
(length) -= sizeof((ctx)->block); \
|
||||
} \
|
||||
memcpy ((ctx)->block, (data), (length)); \
|
||||
(ctx)->index = (length); \
|
||||
__md_done: \
|
||||
; \
|
||||
} while (0)
|
||||
|
||||
/* Pads the block to a block boundary with the bit pattern 1 0*,
|
||||
leaving size octets for the length field at the end. If needed,
|
||||
compresses the block and starts a new one. */
|
||||
#define MD_PAD(ctx, size, f) \
|
||||
do { \
|
||||
unsigned __md_i; \
|
||||
__md_i = (ctx)->index; \
|
||||
\
|
||||
/* Set the first char of padding to 0x80. This is safe since there \
|
||||
is always at least one byte free */ \
|
||||
\
|
||||
assert(__md_i < sizeof((ctx)->block)); \
|
||||
(ctx)->block[__md_i++] = 0x80; \
|
||||
\
|
||||
if (__md_i > (sizeof((ctx)->block) - (size))) \
|
||||
{ /* No room for length in this block. Process it and \
|
||||
pad with another one */ \
|
||||
memset((ctx)->block + __md_i, 0, sizeof((ctx)->block) - __md_i); \
|
||||
\
|
||||
f((ctx), (ctx)->block); \
|
||||
__md_i = 0; \
|
||||
} \
|
||||
memset((ctx)->block + __md_i, 0, \
|
||||
sizeof((ctx)->block) - (size) - __md_i); \
|
||||
\
|
||||
} while (0)
|
||||
|
||||
#endif /* NETTLE_MACROS_H_INCLUDED */
|
||||
@@ -1,79 +0,0 @@
|
||||
/* md2.h
|
||||
|
||||
The MD2 hash function, described in RFC 1319.
|
||||
|
||||
Copyright (C) 2003 Niels Möller
|
||||
|
||||
This file is part of GNU Nettle.
|
||||
|
||||
GNU Nettle is free software: you can redistribute it and/or
|
||||
modify it under the terms of either:
|
||||
|
||||
* the GNU Lesser General Public License as published by the Free
|
||||
Software Foundation; either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or
|
||||
|
||||
* the GNU General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or both in parallel, as here.
|
||||
|
||||
GNU Nettle is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received copies of the GNU General Public License and
|
||||
the GNU Lesser General Public License along with this program. If
|
||||
not, see http://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
#ifndef NETTLE_MD2_H_INCLUDED
|
||||
#define NETTLE_MD2_H_INCLUDED
|
||||
|
||||
#include "nettle-types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Name mangling */
|
||||
#define md2_init nettle_md2_init
|
||||
#define md2_update nettle_md2_update
|
||||
#define md2_digest nettle_md2_digest
|
||||
|
||||
#define MD2_DIGEST_SIZE 16
|
||||
#define MD2_BLOCK_SIZE 16
|
||||
/* For backwards compatibility */
|
||||
#define MD2_DATA_SIZE MD2_BLOCK_SIZE
|
||||
|
||||
struct md2_ctx
|
||||
{
|
||||
uint8_t C[MD2_BLOCK_SIZE];
|
||||
uint8_t X[3 * MD2_BLOCK_SIZE];
|
||||
uint8_t block[MD2_BLOCK_SIZE]; /* Block buffer */
|
||||
unsigned index; /* Into buffer */
|
||||
};
|
||||
|
||||
void
|
||||
md2_init(struct md2_ctx *ctx);
|
||||
|
||||
void
|
||||
md2_update(struct md2_ctx *ctx,
|
||||
size_t length,
|
||||
const uint8_t *data);
|
||||
|
||||
void
|
||||
md2_digest(struct md2_ctx *ctx,
|
||||
size_t length,
|
||||
uint8_t *digest);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* NETTLE_MD2_H_INCLUDED */
|
||||
@@ -1,83 +0,0 @@
|
||||
/* md4.h
|
||||
|
||||
The MD4 hash function, described in RFC 1320.
|
||||
|
||||
Copyright (C) 2003 Niels Möller
|
||||
|
||||
This file is part of GNU Nettle.
|
||||
|
||||
GNU Nettle is free software: you can redistribute it and/or
|
||||
modify it under the terms of either:
|
||||
|
||||
* the GNU Lesser General Public License as published by the Free
|
||||
Software Foundation; either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or
|
||||
|
||||
* the GNU General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or both in parallel, as here.
|
||||
|
||||
GNU Nettle is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received copies of the GNU General Public License and
|
||||
the GNU Lesser General Public License along with this program. If
|
||||
not, see http://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
#ifndef NETTLE_MD4_H_INCLUDED
|
||||
#define NETTLE_MD4_H_INCLUDED
|
||||
|
||||
#include "nettle-types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Name mangling */
|
||||
#define md4_init nettle_md4_init
|
||||
#define md4_update nettle_md4_update
|
||||
#define md4_digest nettle_md4_digest
|
||||
|
||||
#define MD4_DIGEST_SIZE 16
|
||||
#define MD4_BLOCK_SIZE 64
|
||||
/* For backwards compatibility */
|
||||
#define MD4_DATA_SIZE MD4_BLOCK_SIZE
|
||||
|
||||
/* Digest is kept internally as 4 32-bit words. */
|
||||
#define _MD4_DIGEST_LENGTH 4
|
||||
|
||||
/* FIXME: Identical to md5_ctx */
|
||||
struct md4_ctx
|
||||
{
|
||||
uint32_t state[_MD4_DIGEST_LENGTH];
|
||||
uint64_t count; /* Block count */
|
||||
uint8_t block[MD4_BLOCK_SIZE]; /* Block buffer */
|
||||
unsigned index; /* Into buffer */
|
||||
};
|
||||
|
||||
void
|
||||
md4_init(struct md4_ctx *ctx);
|
||||
|
||||
void
|
||||
md4_update(struct md4_ctx *ctx,
|
||||
size_t length,
|
||||
const uint8_t *data);
|
||||
|
||||
void
|
||||
md4_digest(struct md4_ctx *ctx,
|
||||
size_t length,
|
||||
uint8_t *digest);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* NETTLE_MD4_H_INCLUDED */
|
||||
@@ -1,58 +0,0 @@
|
||||
/* md5-compat.h
|
||||
|
||||
The md5 hash function, RFC 1321-style interface.
|
||||
|
||||
Copyright (C) 2001 Niels Möller
|
||||
|
||||
This file is part of GNU Nettle.
|
||||
|
||||
GNU Nettle is free software: you can redistribute it and/or
|
||||
modify it under the terms of either:
|
||||
|
||||
* the GNU Lesser General Public License as published by the Free
|
||||
Software Foundation; either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or
|
||||
|
||||
* the GNU General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or both in parallel, as here.
|
||||
|
||||
GNU Nettle is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received copies of the GNU General Public License and
|
||||
the GNU Lesser General Public License along with this program. If
|
||||
not, see http://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
#ifndef NETTLE_MD5_COMPAT_H_INCLUDED
|
||||
#define NETTLE_MD5_COMPAT_H_INCLUDED
|
||||
|
||||
#include "md5.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Name mangling */
|
||||
#define MD5Init nettle_MD5Init
|
||||
#define MD5Update nettle_MD5Update
|
||||
#define MD5Final nettle_MD5Final
|
||||
|
||||
typedef struct md5_ctx MD5_CTX;
|
||||
|
||||
void MD5Init(MD5_CTX *ctx);
|
||||
void MD5Update(MD5_CTX *ctx, const unsigned char *data, unsigned int length);
|
||||
void MD5Final(unsigned char *out, MD5_CTX *ctx);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* NETTLE_MD5_COMPAT_H_INCLUDED */
|
||||
@@ -1,86 +0,0 @@
|
||||
/* md5.h
|
||||
|
||||
The MD5 hash function, described in RFC 1321.
|
||||
|
||||
Copyright (C) 2001 Niels Möller
|
||||
|
||||
This file is part of GNU Nettle.
|
||||
|
||||
GNU Nettle is free software: you can redistribute it and/or
|
||||
modify it under the terms of either:
|
||||
|
||||
* the GNU Lesser General Public License as published by the Free
|
||||
Software Foundation; either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or
|
||||
|
||||
* the GNU General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or both in parallel, as here.
|
||||
|
||||
GNU Nettle is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received copies of the GNU General Public License and
|
||||
the GNU Lesser General Public License along with this program. If
|
||||
not, see http://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
#ifndef NETTLE_MD5_H_INCLUDED
|
||||
#define NETTLE_MD5_H_INCLUDED
|
||||
|
||||
#include "nettle-types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Name mangling */
|
||||
#define md5_init nettle_md5_init
|
||||
#define md5_update nettle_md5_update
|
||||
#define md5_digest nettle_md5_digest
|
||||
|
||||
#define MD5_DIGEST_SIZE 16
|
||||
#define MD5_BLOCK_SIZE 64
|
||||
/* For backwards compatibility */
|
||||
#define MD5_DATA_SIZE MD5_BLOCK_SIZE
|
||||
|
||||
/* Digest is kept internally as 4 32-bit words. */
|
||||
#define _MD5_DIGEST_LENGTH 4
|
||||
|
||||
struct md5_ctx
|
||||
{
|
||||
uint32_t state[_MD5_DIGEST_LENGTH];
|
||||
uint64_t count; /* Block count */
|
||||
uint8_t block[MD5_BLOCK_SIZE]; /* Block buffer */
|
||||
unsigned index; /* Into buffer */
|
||||
};
|
||||
|
||||
void
|
||||
md5_init(struct md5_ctx *ctx);
|
||||
|
||||
void
|
||||
md5_update(struct md5_ctx *ctx,
|
||||
size_t length,
|
||||
const uint8_t *data);
|
||||
|
||||
void
|
||||
md5_digest(struct md5_ctx *ctx,
|
||||
size_t length,
|
||||
uint8_t *digest);
|
||||
|
||||
/* Internal compression function. STATE points to 4 uint32_t words,
|
||||
and DATA points to 64 bytes of input data, possibly unaligned. */
|
||||
void
|
||||
_nettle_md5_compress(uint32_t *state, const uint8_t *data);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* NETTLE_MD5_H_INCLUDED */
|
||||
@@ -1,57 +0,0 @@
|
||||
/* memops.h
|
||||
|
||||
Copyright (C) 2016 Niels Möller
|
||||
|
||||
This file is part of GNU Nettle.
|
||||
|
||||
GNU Nettle is free software: you can redistribute it and/or
|
||||
modify it under the terms of either:
|
||||
|
||||
* the GNU Lesser General Public License as published by the Free
|
||||
Software Foundation; either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or
|
||||
|
||||
* the GNU General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or both in parallel, as here.
|
||||
|
||||
GNU Nettle is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received copies of the GNU General Public License and
|
||||
the GNU Lesser General Public License along with this program. If
|
||||
not, see http://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
#ifndef NETTLE_MEMOPS_H_INCLUDED
|
||||
#define NETTLE_MEMOPS_H_INCLUDED
|
||||
|
||||
#include "memxor.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Name mangling */
|
||||
#define cnd_memcpy nettle_cnd_memcpy
|
||||
#define memeql_sec nettle_memeql_sec
|
||||
|
||||
int
|
||||
memeql_sec (const void *a, const void *b, size_t n);
|
||||
|
||||
/* Side-channel silent conditional memcpy. cnd must be 0 (nop) or 1
|
||||
(copy). */
|
||||
void
|
||||
cnd_memcpy(int cnd, volatile void *dst, const volatile void *src, size_t n);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* NETTLE_MEMOPS_H_INCLUDED */
|
||||
@@ -1,25 +0,0 @@
|
||||
/* memxor.h
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef NETTLE_MEMXOR_H_INCLUDED
|
||||
#define NETTLE_MEMXOR_H_INCLUDED
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Name mangling */
|
||||
#define memxor nettle_memxor
|
||||
#define memxor3 nettle_memxor3
|
||||
|
||||
void *memxor(void *dst, const void *src, size_t n);
|
||||
void *memxor3(void *dst, const void *a, const void *b, size_t n);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* NETTLE_MEMXOR_H_INCLUDED */
|
||||
@@ -1,277 +0,0 @@
|
||||
/* nettle-meta.h
|
||||
|
||||
Information about algorithms.
|
||||
|
||||
Copyright (C) 2002, 2014 Niels Möller
|
||||
|
||||
This file is part of GNU Nettle.
|
||||
|
||||
GNU Nettle is free software: you can redistribute it and/or
|
||||
modify it under the terms of either:
|
||||
|
||||
* the GNU Lesser General Public License as published by the Free
|
||||
Software Foundation; either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or
|
||||
|
||||
* the GNU General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or both in parallel, as here.
|
||||
|
||||
GNU Nettle is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received copies of the GNU General Public License and
|
||||
the GNU Lesser General Public License along with this program. If
|
||||
not, see http://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
#ifndef NETTLE_META_H_INCLUDED
|
||||
#define NETTLE_META_H_INCLUDED
|
||||
|
||||
#include "nettle-types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
struct nettle_cipher
|
||||
{
|
||||
const char *name;
|
||||
|
||||
unsigned context_size;
|
||||
|
||||
/* Zero for stream ciphers */
|
||||
unsigned block_size;
|
||||
|
||||
/* Suggested key size; other sizes are sometimes possible. */
|
||||
unsigned key_size;
|
||||
|
||||
nettle_set_key_func *set_encrypt_key;
|
||||
nettle_set_key_func *set_decrypt_key;
|
||||
|
||||
nettle_cipher_func *encrypt;
|
||||
nettle_cipher_func *decrypt;
|
||||
};
|
||||
|
||||
/* FIXME: Rename with leading underscore, but keep current name (and
|
||||
size!) for now, for ABI compatibility with nettle-3.1, soname
|
||||
libnettle.so.6. */
|
||||
/* null-terminated list of ciphers implemented by this version of nettle */
|
||||
extern const struct nettle_cipher * const nettle_ciphers[];
|
||||
|
||||
const struct nettle_cipher * const *
|
||||
#ifdef __GNUC__
|
||||
__attribute__((pure))
|
||||
#endif
|
||||
nettle_get_ciphers (void);
|
||||
|
||||
#define nettle_ciphers (nettle_get_ciphers())
|
||||
|
||||
extern const struct nettle_cipher nettle_aes128;
|
||||
extern const struct nettle_cipher nettle_aes192;
|
||||
extern const struct nettle_cipher nettle_aes256;
|
||||
|
||||
extern const struct nettle_cipher nettle_camellia128;
|
||||
extern const struct nettle_cipher nettle_camellia192;
|
||||
extern const struct nettle_cipher nettle_camellia256;
|
||||
|
||||
extern const struct nettle_cipher nettle_cast128;
|
||||
|
||||
extern const struct nettle_cipher nettle_serpent128;
|
||||
extern const struct nettle_cipher nettle_serpent192;
|
||||
extern const struct nettle_cipher nettle_serpent256;
|
||||
|
||||
extern const struct nettle_cipher nettle_twofish128;
|
||||
extern const struct nettle_cipher nettle_twofish192;
|
||||
extern const struct nettle_cipher nettle_twofish256;
|
||||
|
||||
extern const struct nettle_cipher nettle_arctwo40;
|
||||
extern const struct nettle_cipher nettle_arctwo64;
|
||||
extern const struct nettle_cipher nettle_arctwo128;
|
||||
extern const struct nettle_cipher nettle_arctwo_gutmann128;
|
||||
|
||||
struct nettle_hash
|
||||
{
|
||||
const char *name;
|
||||
|
||||
/* Size of the context struct */
|
||||
unsigned context_size;
|
||||
|
||||
/* Size of digests */
|
||||
unsigned digest_size;
|
||||
|
||||
/* Internal block size */
|
||||
unsigned block_size;
|
||||
|
||||
nettle_hash_init_func *init;
|
||||
nettle_hash_update_func *update;
|
||||
nettle_hash_digest_func *digest;
|
||||
};
|
||||
|
||||
#define _NETTLE_HASH(name, NAME) { \
|
||||
#name, \
|
||||
sizeof(struct name##_ctx), \
|
||||
NAME##_DIGEST_SIZE, \
|
||||
NAME##_BLOCK_SIZE, \
|
||||
(nettle_hash_init_func *) name##_init, \
|
||||
(nettle_hash_update_func *) name##_update, \
|
||||
(nettle_hash_digest_func *) name##_digest \
|
||||
}
|
||||
|
||||
/* FIXME: Rename with leading underscore, but keep current name (and
|
||||
size!) for now, for ABI compatibility with nettle-3.1, soname
|
||||
libnettle.so.6. */
|
||||
/* null-terminated list of digests implemented by this version of nettle */
|
||||
extern const struct nettle_hash * const nettle_hashes[];
|
||||
|
||||
const struct nettle_hash * const *
|
||||
#ifdef __GNUC__
|
||||
__attribute__((pure))
|
||||
#endif
|
||||
nettle_get_hashes (void);
|
||||
|
||||
#define nettle_hashes (nettle_get_hashes())
|
||||
|
||||
const struct nettle_hash *
|
||||
nettle_lookup_hash (const char *name);
|
||||
|
||||
extern const struct nettle_hash nettle_md2;
|
||||
extern const struct nettle_hash nettle_md4;
|
||||
extern const struct nettle_hash nettle_md5;
|
||||
extern const struct nettle_hash nettle_gosthash94;
|
||||
extern const struct nettle_hash nettle_ripemd160;
|
||||
extern const struct nettle_hash nettle_sha1;
|
||||
extern const struct nettle_hash nettle_sha224;
|
||||
extern const struct nettle_hash nettle_sha256;
|
||||
extern const struct nettle_hash nettle_sha384;
|
||||
extern const struct nettle_hash nettle_sha512;
|
||||
extern const struct nettle_hash nettle_sha512_224;
|
||||
extern const struct nettle_hash nettle_sha512_256;
|
||||
extern const struct nettle_hash nettle_sha3_224;
|
||||
extern const struct nettle_hash nettle_sha3_256;
|
||||
extern const struct nettle_hash nettle_sha3_384;
|
||||
extern const struct nettle_hash nettle_sha3_512;
|
||||
|
||||
struct nettle_aead
|
||||
{
|
||||
const char *name;
|
||||
|
||||
unsigned context_size;
|
||||
/* Block size for encrypt and decrypt. */
|
||||
unsigned block_size;
|
||||
unsigned key_size;
|
||||
unsigned nonce_size;
|
||||
unsigned digest_size;
|
||||
|
||||
nettle_set_key_func *set_encrypt_key;
|
||||
nettle_set_key_func *set_decrypt_key;
|
||||
nettle_set_key_func *set_nonce;
|
||||
nettle_hash_update_func *update;
|
||||
nettle_crypt_func *encrypt;
|
||||
nettle_crypt_func *decrypt;
|
||||
/* FIXME: Drop length argument? */
|
||||
nettle_hash_digest_func *digest;
|
||||
};
|
||||
|
||||
/* FIXME: Rename with leading underscore, but keep current name (and
|
||||
size!) for now, for ABI compatibility with nettle-3.1, soname
|
||||
libnettle.so.6. */
|
||||
/* null-terminated list of aead constructions implemented by this
|
||||
version of nettle */
|
||||
extern const struct nettle_aead * const nettle_aeads[];
|
||||
|
||||
const struct nettle_aead * const *
|
||||
#ifdef __GNUC__
|
||||
__attribute__((pure))
|
||||
#endif
|
||||
nettle_get_aeads (void);
|
||||
|
||||
#define nettle_aeads (nettle_get_aeads())
|
||||
|
||||
extern const struct nettle_aead nettle_gcm_aes128;
|
||||
extern const struct nettle_aead nettle_gcm_aes192;
|
||||
extern const struct nettle_aead nettle_gcm_aes256;
|
||||
extern const struct nettle_aead nettle_gcm_camellia128;
|
||||
extern const struct nettle_aead nettle_gcm_camellia256;
|
||||
extern const struct nettle_aead nettle_eax_aes128;
|
||||
extern const struct nettle_aead nettle_chacha_poly1305;
|
||||
|
||||
struct nettle_armor
|
||||
{
|
||||
const char *name;
|
||||
unsigned encode_context_size;
|
||||
unsigned decode_context_size;
|
||||
|
||||
unsigned encode_final_length;
|
||||
|
||||
nettle_armor_init_func *encode_init;
|
||||
nettle_armor_length_func *encode_length;
|
||||
nettle_armor_encode_update_func *encode_update;
|
||||
nettle_armor_encode_final_func *encode_final;
|
||||
|
||||
nettle_armor_init_func *decode_init;
|
||||
nettle_armor_length_func *decode_length;
|
||||
nettle_armor_decode_update_func *decode_update;
|
||||
nettle_armor_decode_final_func *decode_final;
|
||||
};
|
||||
|
||||
#define _NETTLE_ARMOR(name, NAME) { \
|
||||
#name, \
|
||||
sizeof(struct name##_encode_ctx), \
|
||||
sizeof(struct name##_decode_ctx), \
|
||||
NAME##_ENCODE_FINAL_LENGTH, \
|
||||
(nettle_armor_init_func *) name##_encode_init, \
|
||||
(nettle_armor_length_func *) name##_encode_length, \
|
||||
(nettle_armor_encode_update_func *) name##_encode_update, \
|
||||
(nettle_armor_encode_final_func *) name##_encode_final, \
|
||||
(nettle_armor_init_func *) name##_decode_init, \
|
||||
(nettle_armor_length_func *) name##_decode_length, \
|
||||
(nettle_armor_decode_update_func *) name##_decode_update, \
|
||||
(nettle_armor_decode_final_func *) name##_decode_final, \
|
||||
}
|
||||
|
||||
#define _NETTLE_ARMOR_0(name, NAME) { \
|
||||
#name, \
|
||||
0, \
|
||||
sizeof(struct name##_decode_ctx), \
|
||||
NAME##_ENCODE_FINAL_LENGTH, \
|
||||
(nettle_armor_init_func *) name##_encode_init, \
|
||||
(nettle_armor_length_func *) name##_encode_length, \
|
||||
(nettle_armor_encode_update_func *) name##_encode_update, \
|
||||
(nettle_armor_encode_final_func *) name##_encode_final, \
|
||||
(nettle_armor_init_func *) name##_decode_init, \
|
||||
(nettle_armor_length_func *) name##_decode_length, \
|
||||
(nettle_armor_decode_update_func *) name##_decode_update, \
|
||||
(nettle_armor_decode_final_func *) name##_decode_final, \
|
||||
}
|
||||
|
||||
/* FIXME: Rename with leading underscore, but keep current name (and
|
||||
size!) for now, for ABI compatibility with nettle-3.1, soname
|
||||
libnettle.so.6. */
|
||||
/* null-terminated list of armor schemes implemented by this version of nettle */
|
||||
extern const struct nettle_armor * const nettle_armors[];
|
||||
|
||||
const struct nettle_armor * const *
|
||||
#ifdef __GNUC__
|
||||
__attribute__((pure))
|
||||
#endif
|
||||
nettle_get_armors (void);
|
||||
|
||||
#define nettle_armors (nettle_get_armors())
|
||||
|
||||
extern const struct nettle_armor nettle_base64;
|
||||
extern const struct nettle_armor nettle_base64url;
|
||||
extern const struct nettle_armor nettle_base16;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* NETTLE_META_H_INCLUDED */
|
||||
@@ -1,286 +0,0 @@
|
||||
#ifndef __NETTLE_STDINT_H
|
||||
#define __NETTLE_STDINT_H 1
|
||||
#ifndef _GENERATED_STDINT_H
|
||||
#define _GENERATED_STDINT_H " "
|
||||
/* generated using gnu compiler gcc (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0 */
|
||||
#define _STDINT_HAVE_STDINT_H 1
|
||||
|
||||
/* ................... shortcircuit part ........................... */
|
||||
|
||||
#if defined HAVE_STDINT_H || defined _STDINT_HAVE_STDINT_H
|
||||
#include <stdint.h>
|
||||
#else
|
||||
#include <stddef.h>
|
||||
|
||||
/* .................... configured part ............................ */
|
||||
|
||||
/* whether we have a C99 compatible stdint header file */
|
||||
/* #undef _STDINT_HEADER_INTPTR */
|
||||
/* whether we have a C96 compatible inttypes header file */
|
||||
/* #undef _STDINT_HEADER_UINT32 */
|
||||
/* whether we have a BSD compatible inet types header */
|
||||
/* #undef _STDINT_HEADER_U_INT32 */
|
||||
|
||||
/* which 64bit typedef has been found */
|
||||
/* #undef _STDINT_HAVE_UINT64_T */
|
||||
/* #undef _STDINT_HAVE_U_INT64_T */
|
||||
|
||||
/* which type model has been detected */
|
||||
/* #undef _STDINT_CHAR_MODEL // skipped */
|
||||
/* #undef _STDINT_LONG_MODEL // skipped */
|
||||
|
||||
/* whether int_least types were detected */
|
||||
/* #undef _STDINT_HAVE_INT_LEAST32_T */
|
||||
/* whether int_fast types were detected */
|
||||
/* #undef _STDINT_HAVE_INT_FAST32_T */
|
||||
/* whether intmax_t type was detected */
|
||||
/* #undef _STDINT_HAVE_INTMAX_T */
|
||||
|
||||
/* .................... detections part ............................ */
|
||||
|
||||
/* whether we need to define bitspecific types from compiler base types */
|
||||
#ifndef _STDINT_HEADER_INTPTR
|
||||
#ifndef _STDINT_HEADER_UINT32
|
||||
#ifndef _STDINT_HEADER_U_INT32
|
||||
#define _STDINT_NEED_INT_MODEL_T
|
||||
#else
|
||||
#define _STDINT_HAVE_U_INT_TYPES
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef _STDINT_HAVE_U_INT_TYPES
|
||||
#undef _STDINT_NEED_INT_MODEL_T
|
||||
#endif
|
||||
|
||||
#ifdef _STDINT_CHAR_MODEL
|
||||
#if _STDINT_CHAR_MODEL+0 == 122 || _STDINT_CHAR_MODEL+0 == 124
|
||||
#ifndef _STDINT_BYTE_MODEL
|
||||
#define _STDINT_BYTE_MODEL 12
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef _STDINT_HAVE_INT_LEAST32_T
|
||||
#define _STDINT_NEED_INT_LEAST_T
|
||||
#endif
|
||||
|
||||
#ifndef _STDINT_HAVE_INT_FAST32_T
|
||||
#define _STDINT_NEED_INT_FAST_T
|
||||
#endif
|
||||
|
||||
#ifndef _STDINT_HEADER_INTPTR
|
||||
#define _STDINT_NEED_INTPTR_T
|
||||
#ifndef _STDINT_HAVE_INTMAX_T
|
||||
#define _STDINT_NEED_INTMAX_T
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
/* .................... definition part ............................ */
|
||||
|
||||
/* some system headers have good uint64_t */
|
||||
#ifndef _HAVE_UINT64_T
|
||||
#if defined _STDINT_HAVE_UINT64_T || defined HAVE_UINT64_T
|
||||
#define _HAVE_UINT64_T
|
||||
#elif defined _STDINT_HAVE_U_INT64_T || defined HAVE_U_INT64_T
|
||||
#define _HAVE_UINT64_T
|
||||
typedef u_int64_t uint64_t;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef _HAVE_UINT64_T
|
||||
/* .. here are some common heuristics using compiler runtime specifics */
|
||||
#if defined __STDC_VERSION__ && defined __STDC_VERSION__ >= 199901L
|
||||
#define _HAVE_UINT64_T
|
||||
typedef long long int64_t;
|
||||
typedef unsigned long long uint64_t;
|
||||
|
||||
#elif !defined __STRICT_ANSI__
|
||||
#if defined _MSC_VER || defined __WATCOMC__ || defined __BORLANDC__
|
||||
#define _HAVE_UINT64_T
|
||||
typedef __int64 int64_t;
|
||||
typedef unsigned __int64 uint64_t;
|
||||
|
||||
#elif defined __GNUC__ || defined __MWERKS__ || defined __ELF__
|
||||
/* note: all ELF-systems seem to have loff-support which needs 64-bit */
|
||||
#if !defined _NO_LONGLONG
|
||||
#define _HAVE_UINT64_T
|
||||
typedef long long int64_t;
|
||||
typedef unsigned long long uint64_t;
|
||||
#endif
|
||||
|
||||
#elif defined __alpha || (defined __mips && defined _ABIN32)
|
||||
#if !defined _NO_LONGLONG
|
||||
typedef long int64_t;
|
||||
typedef unsigned long uint64_t;
|
||||
#endif
|
||||
/* compiler/cpu type to define int64_t */
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined _STDINT_HAVE_U_INT_TYPES
|
||||
/* int8_t int16_t int32_t defined by inet code, redeclare the u_intXX types */
|
||||
typedef u_int8_t uint8_t;
|
||||
typedef u_int16_t uint16_t;
|
||||
typedef u_int32_t uint32_t;
|
||||
|
||||
/* glibc compatibility */
|
||||
#ifndef __int8_t_defined
|
||||
#define __int8_t_defined
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef _STDINT_NEED_INT_MODEL_T
|
||||
/* we must guess all the basic types. Apart from byte-adressable system, */
|
||||
/* there a few 32-bit-only dsp-systems that we guard with BYTE_MODEL 8-} */
|
||||
/* (btw, those nibble-addressable systems are way off, or so we assume) */
|
||||
|
||||
|
||||
#if defined _STDINT_BYTE_MODEL
|
||||
#if _STDINT_LONG_MODEL+0 == 242
|
||||
/* 2:4:2 = IP16 = a normal 16-bit system */
|
||||
typedef unsigned char uint8_t;
|
||||
typedef unsigned short uint16_t;
|
||||
typedef unsigned long uint32_t;
|
||||
#ifndef __int8_t_defined
|
||||
#define __int8_t_defined
|
||||
typedef char int8_t;
|
||||
typedef short int16_t;
|
||||
typedef long int32_t;
|
||||
#endif
|
||||
#elif _STDINT_LONG_MODEL+0 == 244 || _STDINT_LONG_MODEL == 444
|
||||
/* 2:4:4 = LP32 = a 32-bit system derived from a 16-bit */
|
||||
/* 4:4:4 = ILP32 = a normal 32-bit system */
|
||||
typedef unsigned char uint8_t;
|
||||
typedef unsigned short uint16_t;
|
||||
typedef unsigned int uint32_t;
|
||||
#ifndef __int8_t_defined
|
||||
#define __int8_t_defined
|
||||
typedef char int8_t;
|
||||
typedef short int16_t;
|
||||
typedef int int32_t;
|
||||
#endif
|
||||
#elif _STDINT_LONG_MODEL+0 == 484 || _STDINT_LONG_MODEL+0 == 488
|
||||
/* 4:8:4 = IP32 = a 32-bit system prepared for 64-bit */
|
||||
/* 4:8:8 = LP64 = a normal 64-bit system */
|
||||
typedef unsigned char uint8_t;
|
||||
typedef unsigned short uint16_t;
|
||||
typedef unsigned int uint32_t;
|
||||
#ifndef __int8_t_defined
|
||||
#define __int8_t_defined
|
||||
typedef char int8_t;
|
||||
typedef short int16_t;
|
||||
typedef int int32_t;
|
||||
#endif
|
||||
/* this system has a "long" of 64bit */
|
||||
#ifndef _HAVE_UINT64_T
|
||||
#define _HAVE_UINT64_T
|
||||
typedef unsigned long uint64_t;
|
||||
typedef long int64_t;
|
||||
#endif
|
||||
#elif _STDINT_LONG_MODEL+0 == 448
|
||||
/* LLP64 a 64-bit system derived from a 32-bit system */
|
||||
typedef unsigned char uint8_t;
|
||||
typedef unsigned short uint16_t;
|
||||
typedef unsigned int uint32_t;
|
||||
#ifndef __int8_t_defined
|
||||
#define __int8_t_defined
|
||||
typedef char int8_t;
|
||||
typedef short int16_t;
|
||||
typedef int int32_t;
|
||||
#endif
|
||||
/* assuming the system has a "long long" */
|
||||
#ifndef _HAVE_UINT64_T
|
||||
#define _HAVE_UINT64_T
|
||||
typedef unsigned long long uint64_t;
|
||||
typedef long long int64_t;
|
||||
#endif
|
||||
#else
|
||||
#define _STDINT_NO_INT32_T
|
||||
#endif
|
||||
#else
|
||||
#define _STDINT_NO_INT8_T
|
||||
#define _STDINT_NO_INT32_T
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/*
|
||||
* quote from SunOS-5.8 sys/inttypes.h:
|
||||
* Use at your own risk. As of February 1996, the committee is squarely
|
||||
* behind the fixed sized types; the "least" and "fast" types are still being
|
||||
* discussed. The probability that the "fast" types may be removed before
|
||||
* the standard is finalized is high enough that they are not currently
|
||||
* implemented.
|
||||
*/
|
||||
|
||||
#if defined _STDINT_NEED_INT_LEAST_T
|
||||
typedef int8_t int_least8_t;
|
||||
typedef int16_t int_least16_t;
|
||||
typedef int32_t int_least32_t;
|
||||
#ifdef _HAVE_UINT64_T
|
||||
typedef int64_t int_least64_t;
|
||||
#endif
|
||||
|
||||
typedef uint8_t uint_least8_t;
|
||||
typedef uint16_t uint_least16_t;
|
||||
typedef uint32_t uint_least32_t;
|
||||
#ifdef _HAVE_UINT64_T
|
||||
typedef uint64_t uint_least64_t;
|
||||
#endif
|
||||
/* least types */
|
||||
#endif
|
||||
|
||||
#if defined _STDINT_NEED_INT_FAST_T
|
||||
typedef int8_t int_fast8_t;
|
||||
typedef int int_fast16_t;
|
||||
typedef int32_t int_fast32_t;
|
||||
#ifdef _HAVE_UINT64_T
|
||||
typedef int64_t int_fast64_t;
|
||||
#endif
|
||||
|
||||
typedef uint8_t uint_fast8_t;
|
||||
typedef unsigned uint_fast16_t;
|
||||
typedef uint32_t uint_fast32_t;
|
||||
#ifdef _HAVE_UINT64_T
|
||||
typedef uint64_t uint_fast64_t;
|
||||
#endif
|
||||
/* fast types */
|
||||
#endif
|
||||
|
||||
#ifdef _STDINT_NEED_INTMAX_T
|
||||
#ifdef _HAVE_UINT64_T
|
||||
typedef int64_t intmax_t;
|
||||
typedef uint64_t uintmax_t;
|
||||
#else
|
||||
typedef long intmax_t;
|
||||
typedef unsigned long uintmax_t;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef _STDINT_NEED_INTPTR_T
|
||||
#ifndef __intptr_t_defined
|
||||
#define __intptr_t_defined
|
||||
/* we encourage using "long" to store pointer values, never use "int" ! */
|
||||
#if _STDINT_LONG_MODEL+0 == 242 || _STDINT_LONG_MODEL+0 == 484
|
||||
typedef unsigned int uintptr_t;
|
||||
typedef int intptr_t;
|
||||
#elif _STDINT_LONG_MODEL+0 == 244 || _STDINT_LONG_MODEL+0 == 444
|
||||
typedef unsigned long uintptr_t;
|
||||
typedef long intptr_t;
|
||||
#elif _STDINT_LONG_MODEL+0 == 448 && defined _HAVE_UINT64_T
|
||||
typedef uint64_t uintptr_t;
|
||||
typedef int64_t intptr_t;
|
||||
#else /* matches typical system types ILP32 and LP64 - but not IP16 or LLP64 */
|
||||
typedef unsigned long uintptr_t;
|
||||
typedef long intptr_t;
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* shortcircuit*/
|
||||
#endif
|
||||
/* once */
|
||||
#endif
|
||||
#endif
|
||||
@@ -1,110 +0,0 @@
|
||||
/* nettle-types.h
|
||||
|
||||
Copyright (C) 2005, 2014 Niels Möller
|
||||
|
||||
This file is part of GNU Nettle.
|
||||
|
||||
GNU Nettle is free software: you can redistribute it and/or
|
||||
modify it under the terms of either:
|
||||
|
||||
* the GNU Lesser General Public License as published by the Free
|
||||
Software Foundation; either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or
|
||||
|
||||
* the GNU General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or both in parallel, as here.
|
||||
|
||||
GNU Nettle is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received copies of the GNU General Public License and
|
||||
the GNU Lesser General Public License along with this program. If
|
||||
not, see http://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
#ifndef NETTLE_TYPES_H
|
||||
#define NETTLE_TYPES_H
|
||||
|
||||
/* For size_t */
|
||||
#include <stddef.h>
|
||||
|
||||
/* Pretend these types always exists. Nettle doesn't use them. */
|
||||
#define _STDINT_HAVE_INT_FAST32_T 1
|
||||
#include "nettle-stdint.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* An aligned 16-byte block. */
|
||||
union nettle_block16
|
||||
{
|
||||
uint8_t b[16];
|
||||
unsigned long w[16 / sizeof(unsigned long)];
|
||||
};
|
||||
|
||||
/* Randomness. Used by key generation and dsa signature creation. */
|
||||
typedef void nettle_random_func(void *ctx,
|
||||
size_t length, uint8_t *dst);
|
||||
|
||||
/* Progress report function, mainly for key generation. */
|
||||
typedef void nettle_progress_func(void *ctx, int c);
|
||||
|
||||
/* Realloc function, used by struct nettle_buffer. */
|
||||
typedef void *nettle_realloc_func(void *ctx, void *p, size_t length);
|
||||
|
||||
/* Ciphers */
|
||||
typedef void nettle_set_key_func(void *ctx, const uint8_t *key);
|
||||
|
||||
/* For block ciphers, const context. */
|
||||
typedef void nettle_cipher_func(const void *ctx,
|
||||
size_t length, uint8_t *dst,
|
||||
const uint8_t *src);
|
||||
|
||||
|
||||
/* Uses a void * for cipher contexts. Used for crypt operations where
|
||||
the internal state changes during the encryption. */
|
||||
typedef void nettle_crypt_func(void *ctx,
|
||||
size_t length, uint8_t *dst,
|
||||
const uint8_t *src);
|
||||
|
||||
/* Hash algorithms */
|
||||
typedef void nettle_hash_init_func(void *ctx);
|
||||
typedef void nettle_hash_update_func(void *ctx,
|
||||
size_t length,
|
||||
const uint8_t *src);
|
||||
typedef void nettle_hash_digest_func(void *ctx,
|
||||
size_t length, uint8_t *dst);
|
||||
|
||||
/* ASCII armor codecs. NOTE: Experimental and subject to change. */
|
||||
|
||||
typedef size_t nettle_armor_length_func(size_t length);
|
||||
typedef void nettle_armor_init_func(void *ctx);
|
||||
|
||||
typedef size_t nettle_armor_encode_update_func(void *ctx,
|
||||
char *dst,
|
||||
size_t src_length,
|
||||
const uint8_t *src);
|
||||
|
||||
typedef size_t nettle_armor_encode_final_func(void *ctx, char *dst);
|
||||
|
||||
typedef int nettle_armor_decode_update_func(void *ctx,
|
||||
size_t *dst_length,
|
||||
uint8_t *dst,
|
||||
size_t src_length,
|
||||
const char *src);
|
||||
|
||||
typedef int nettle_armor_decode_final_func(void *ctx);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* NETTLE_TYPES_H */
|
||||
@@ -1,85 +0,0 @@
|
||||
/* pbkdf2.h
|
||||
|
||||
PKCS #5 password-based key derivation function PBKDF2, see RFC 2898.
|
||||
|
||||
Copyright (C) 2012 Simon Josefsson
|
||||
|
||||
This file is part of GNU Nettle.
|
||||
|
||||
GNU Nettle is free software: you can redistribute it and/or
|
||||
modify it under the terms of either:
|
||||
|
||||
* the GNU Lesser General Public License as published by the Free
|
||||
Software Foundation; either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or
|
||||
|
||||
* the GNU General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or both in parallel, as here.
|
||||
|
||||
GNU Nettle is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received copies of the GNU General Public License and
|
||||
the GNU Lesser General Public License along with this program. If
|
||||
not, see http://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
#ifndef NETTLE_PBKDF2_H_INCLUDED
|
||||
#define NETTLE_PBKDF2_H_INCLUDED
|
||||
|
||||
#include "nettle-meta.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
/* Namespace mangling */
|
||||
#define pbkdf2 nettle_pbkdf2
|
||||
#define pbkdf2_hmac_sha1 nettle_pbkdf2_hmac_sha1
|
||||
#define pbkdf2_hmac_sha256 nettle_pbkdf2_hmac_sha256
|
||||
|
||||
void
|
||||
pbkdf2 (void *mac_ctx,
|
||||
nettle_hash_update_func *update,
|
||||
nettle_hash_digest_func *digest,
|
||||
size_t digest_size, unsigned iterations,
|
||||
size_t salt_length, const uint8_t *salt,
|
||||
size_t length, uint8_t *dst);
|
||||
|
||||
#define PBKDF2(ctx, update, digest, digest_size, \
|
||||
iterations, salt_length, salt, length, dst) \
|
||||
(0 ? ((update)((ctx), 0, (uint8_t *) 0), \
|
||||
(digest)((ctx), 0, (uint8_t *) 0)) \
|
||||
: pbkdf2 ((ctx), \
|
||||
(nettle_hash_update_func *)(update), \
|
||||
(nettle_hash_digest_func *)(digest), \
|
||||
(digest_size), (iterations), \
|
||||
(salt_length), (salt), (length), (dst)))
|
||||
|
||||
/* PBKDF2 with specific PRFs. */
|
||||
|
||||
void
|
||||
pbkdf2_hmac_sha1 (size_t key_length, const uint8_t *key,
|
||||
unsigned iterations,
|
||||
size_t salt_length, const uint8_t *salt,
|
||||
size_t length, uint8_t *dst);
|
||||
|
||||
void
|
||||
pbkdf2_hmac_sha256 (size_t key_length, const uint8_t *key,
|
||||
unsigned iterations,
|
||||
size_t salt_length, const uint8_t *salt,
|
||||
size_t length, uint8_t *dst);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* NETTLE_PBKDF2_H_INCLUDED */
|
||||
@@ -1,248 +0,0 @@
|
||||
/* pgp.h
|
||||
|
||||
PGP related functions.
|
||||
|
||||
Copyright (C) 2001, 2002 Niels Möller
|
||||
|
||||
This file is part of GNU Nettle.
|
||||
|
||||
GNU Nettle is free software: you can redistribute it and/or
|
||||
modify it under the terms of either:
|
||||
|
||||
* the GNU Lesser General Public License as published by the Free
|
||||
Software Foundation; either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or
|
||||
|
||||
* the GNU General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or both in parallel, as here.
|
||||
|
||||
GNU Nettle is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received copies of the GNU General Public License and
|
||||
the GNU Lesser General Public License along with this program. If
|
||||
not, see http://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
#ifndef NETTLE_PGP_H_INCLUDED
|
||||
#define NETTLE_PGP_H_INCLUDED
|
||||
|
||||
#include <time.h>
|
||||
|
||||
#include "nettle-types.h"
|
||||
#include "bignum.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Name mangling */
|
||||
#define pgp_put_uint32 nettle_pgp_put_uint32
|
||||
#define pgp_put_uint16 nettle_pgp_put_uint16
|
||||
#define pgp_put_mpi nettle_pgp_put_mpi
|
||||
#define pgp_put_string nettle_pgp_put_string
|
||||
#define pgp_put_length nettle_pgp_put_length
|
||||
#define pgp_put_header nettle_pgp_put_header
|
||||
#define pgp_put_header_length nettle_pgp_put_header_length
|
||||
#define pgp_sub_packet_start nettle_pgp_sub_packet_start
|
||||
#define pgp_put_sub_packet nettle_pgp_put_sub_packet
|
||||
#define pgp_sub_packet_end nettle_pgp_sub_packet_end
|
||||
#define pgp_put_public_rsa_key nettle_pgp_put_public_rsa_key
|
||||
#define pgp_put_rsa_sha1_signature nettle_pgp_put_rsa_sha1_signature
|
||||
#define pgp_put_userid nettle_pgp_put_userid
|
||||
#define pgp_crc24 nettle_pgp_crc24
|
||||
#define pgp_armor nettle_pgp_armor
|
||||
|
||||
struct nettle_buffer;
|
||||
struct rsa_public_key;
|
||||
struct rsa_private_key;
|
||||
struct sha1_ctx;
|
||||
|
||||
int
|
||||
pgp_put_uint32(struct nettle_buffer *buffer, uint32_t i);
|
||||
|
||||
int
|
||||
pgp_put_uint16(struct nettle_buffer *buffer, unsigned i);
|
||||
|
||||
int
|
||||
pgp_put_mpi(struct nettle_buffer *buffer, const mpz_t x);
|
||||
|
||||
int
|
||||
pgp_put_string(struct nettle_buffer *buffer,
|
||||
unsigned length,
|
||||
const uint8_t *s);
|
||||
|
||||
int
|
||||
pgp_put_length(struct nettle_buffer *buffer,
|
||||
unsigned length);
|
||||
|
||||
int
|
||||
pgp_put_header(struct nettle_buffer *buffer,
|
||||
unsigned tag, unsigned length);
|
||||
|
||||
void
|
||||
pgp_put_header_length(struct nettle_buffer *buffer,
|
||||
/* start of the header */
|
||||
unsigned start,
|
||||
unsigned field_size);
|
||||
|
||||
unsigned
|
||||
pgp_sub_packet_start(struct nettle_buffer *buffer);
|
||||
|
||||
int
|
||||
pgp_put_sub_packet(struct nettle_buffer *buffer,
|
||||
unsigned type,
|
||||
unsigned length,
|
||||
const uint8_t *data);
|
||||
|
||||
void
|
||||
pgp_sub_packet_end(struct nettle_buffer *buffer, unsigned start);
|
||||
|
||||
int
|
||||
pgp_put_public_rsa_key(struct nettle_buffer *,
|
||||
const struct rsa_public_key *key,
|
||||
time_t timestamp);
|
||||
|
||||
int
|
||||
pgp_put_rsa_sha1_signature(struct nettle_buffer *buffer,
|
||||
const struct rsa_private_key *key,
|
||||
const uint8_t *keyid,
|
||||
unsigned type,
|
||||
struct sha1_ctx *hash);
|
||||
|
||||
int
|
||||
pgp_put_userid(struct nettle_buffer *buffer,
|
||||
unsigned length,
|
||||
const uint8_t *name);
|
||||
|
||||
uint32_t
|
||||
pgp_crc24(unsigned length, const uint8_t *data);
|
||||
|
||||
int
|
||||
pgp_armor(struct nettle_buffer *buffer,
|
||||
const char *tag,
|
||||
unsigned length,
|
||||
const uint8_t *data);
|
||||
|
||||
/* Values that can be passed to pgp_put_header when the size of the
|
||||
* length field, but not the length itself, is known. Also the minimum length
|
||||
* for the given field size. */
|
||||
enum pgp_lengths
|
||||
{
|
||||
PGP_LENGTH_ONE_OCTET = 0,
|
||||
PGP_LENGTH_TWO_OCTETS = 192,
|
||||
PGP_LENGTH_FOUR_OCTETS = 8384,
|
||||
};
|
||||
|
||||
enum pgp_public_key_algorithm
|
||||
{
|
||||
PGP_RSA = 1,
|
||||
PGP_RSA_ENCRYPT = 2,
|
||||
PGP_RSA_SIGN = 3,
|
||||
PGP_EL_GAMAL_ENCRYPT = 16,
|
||||
PGP_DSA = 17,
|
||||
PGP_EL_GAMAL = 20,
|
||||
};
|
||||
|
||||
enum pgp_symmetric_algorithm
|
||||
{
|
||||
PGP_PLAINTEXT = 0,
|
||||
PGP_IDEA = 1,
|
||||
PGP_3DES = 2,
|
||||
PGP_CAST5 = 3,
|
||||
PGP_BLOWFISH = 4,
|
||||
PGP_SAFER_SK = 5,
|
||||
PGP_AES128 = 7,
|
||||
PGP_AES192 = 8,
|
||||
PGP_AES256 = 9,
|
||||
};
|
||||
|
||||
enum pgp_compression_algorithm
|
||||
{
|
||||
PGP_UNCOMPRESSED = 0,
|
||||
PGP_ZIP = 1,
|
||||
PGP_ZLIB = 2,
|
||||
};
|
||||
|
||||
enum pgp_hash_algorithm
|
||||
{
|
||||
PGP_MD5 = 1,
|
||||
PGP_SHA1 = 2,
|
||||
PGP_RIPEMD = 3,
|
||||
PGP_MD2 = 5,
|
||||
PGP_TIGER192 = 6,
|
||||
PGP_HAVAL = 7,
|
||||
};
|
||||
|
||||
enum pgp_tag
|
||||
{
|
||||
PGP_TAG_PUBLIC_SESSION_KEY = 1,
|
||||
PGP_TAG_SIGNATURE = 2,
|
||||
PGP_TAG_SYMMETRIC_SESSION_KEY = 3,
|
||||
PGP_TAG_ONE_PASS_SIGNATURE = 4,
|
||||
PGP_TAG_SECRET_KEY = 5,
|
||||
PGP_TAG_PUBLIC_KEY = 6,
|
||||
PGP_TAG_SECRET_SUBKEY = 7,
|
||||
PGP_TAG_COMPRESSED = 8,
|
||||
PGP_TAG_ENCRYPTED = 9,
|
||||
PGP_TAG_MARKER = 10,
|
||||
PGP_TAG_LITERAL = 11,
|
||||
PGP_TAG_TRUST = 12,
|
||||
PGP_TAG_USERID = 13,
|
||||
PGP_TAG_PUBLIC_SUBKEY = 14,
|
||||
};
|
||||
|
||||
enum pgp_signature_type
|
||||
{
|
||||
PGP_SIGN_BINARY = 0,
|
||||
PGP_SIGN_TEXT = 1,
|
||||
PGP_SIGN_STANDALONE = 2,
|
||||
PGP_SIGN_CERTIFICATION = 0x10,
|
||||
PGP_SIGN_CERTIFICATION_PERSONA = 0x11,
|
||||
PGP_SIGN_CERTIFICATION_CASUAL = 0x12,
|
||||
PGP_SIGN_CERTIFICATION_POSITIVE = 0x13,
|
||||
PGP_SIGN_SUBKEY = 0x18,
|
||||
PGP_SIGN_KEY = 0x1f,
|
||||
PGP_SIGN_REVOCATION = 0x20,
|
||||
PGP_SIGN_REVOCATION_SUBKEY = 0x28,
|
||||
PGP_SIGN_REVOCATION_CERTIFICATE = 0x30,
|
||||
PGP_SIGN_TIMESTAMP = 0x40,
|
||||
};
|
||||
|
||||
enum pgp_subpacket_tag
|
||||
{
|
||||
PGP_SUBPACKET_CREATION_TIME = 2,
|
||||
PGP_SUBPACKET_SIGNATURE_EXPIRATION_TIME = 3,
|
||||
PGP_SUBPACKET_EXPORTABLE_CERTIFICATION = 4,
|
||||
PGP_SUBPACKET_TRUST_SIGNATURE = 5,
|
||||
PGP_SUBPACKET_REGULAR_EXPRESSION = 6,
|
||||
PGP_SUBPACKET_REVOCABLE = 7,
|
||||
PGP_SUBPACKET_KEY_EXPIRATION_TIME = 9,
|
||||
PGP_SUBPACKET_PLACEHOLDER = 10 ,
|
||||
PGP_SUBPACKET_PREFERRED_SYMMETRIC_ALGORITHMS = 11,
|
||||
PGP_SUBPACKET_REVOCATION_KEY = 12,
|
||||
PGP_SUBPACKET_ISSUER_KEY_ID = 16,
|
||||
PGP_SUBPACKET_NOTATION_DATA = 20,
|
||||
PGP_SUBPACKET_PREFERRED_HASH_ALGORITHMS = 21,
|
||||
PGP_SUBPACKET_PREFERRED_COMPRESSION_ALGORITHMS = 22,
|
||||
PGP_SUBPACKET_KEY_SERVER_PREFERENCES = 23,
|
||||
PGP_SUBPACKET_PREFERRED_KEY_SERVER = 24,
|
||||
PGP_SUBPACKET_PRIMARY_USER_ID = 25,
|
||||
PGP_SUBPACKET_POLICY_URL = 26,
|
||||
PGP_SUBPACKET_KEY_FLAGS = 27,
|
||||
PGP_SUBPACKET_SIGNERS_USER_ID = 28,
|
||||
PGP_SUBPACKET_REASON_FOR_REVOCATION = 29,
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* NETTLE_PGP_H_INCLUDED */
|
||||
@@ -1,114 +0,0 @@
|
||||
/* pkcs1.h
|
||||
|
||||
PKCS1 embedding.
|
||||
|
||||
Copyright (C) 2003 Niels Möller
|
||||
|
||||
This file is part of GNU Nettle.
|
||||
|
||||
GNU Nettle is free software: you can redistribute it and/or
|
||||
modify it under the terms of either:
|
||||
|
||||
* the GNU Lesser General Public License as published by the Free
|
||||
Software Foundation; either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or
|
||||
|
||||
* the GNU General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or both in parallel, as here.
|
||||
|
||||
GNU Nettle is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received copies of the GNU General Public License and
|
||||
the GNU Lesser General Public License along with this program. If
|
||||
not, see http://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
#ifndef NETTLE_PKCS1_H_INCLUDED
|
||||
#define NETTLE_PKCS1_H_INCLUDED
|
||||
|
||||
#include "nettle-types.h"
|
||||
#include "bignum.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Name mangling */
|
||||
#define _pkcs1_signature_prefix _nettle_pkcs1_signature_prefix
|
||||
#define pkcs1_rsa_digest_encode nettle_pkcs1_rsa_digest_encode
|
||||
#define pkcs1_rsa_md5_encode nettle_pkcs1_rsa_md5_encode
|
||||
#define pkcs1_rsa_md5_encode_digest nettle_pkcs1_rsa_md5_encode_digest
|
||||
#define pkcs1_rsa_sha1_encode nettle_pkcs1_rsa_sha1_encode
|
||||
#define pkcs1_rsa_sha1_encode_digest nettle_pkcs1_rsa_sha1_encode_digest
|
||||
#define pkcs1_rsa_sha256_encode nettle_pkcs1_rsa_sha256_encode
|
||||
#define pkcs1_rsa_sha256_encode_digest nettle_pkcs1_rsa_sha256_encode_digest
|
||||
#define pkcs1_rsa_sha512_encode nettle_pkcs1_rsa_sha512_encode
|
||||
#define pkcs1_rsa_sha512_encode_digest nettle_pkcs1_rsa_sha512_encode_digest
|
||||
#define pkcs1_encrypt nettle_pkcs1_encrypt
|
||||
#define pkcs1_decrypt nettle_pkcs1_decrypt
|
||||
|
||||
struct md5_ctx;
|
||||
struct sha1_ctx;
|
||||
struct sha256_ctx;
|
||||
struct sha512_ctx;
|
||||
|
||||
uint8_t *
|
||||
_pkcs1_signature_prefix(unsigned key_size,
|
||||
uint8_t *buffer,
|
||||
unsigned id_size,
|
||||
const uint8_t *id,
|
||||
unsigned digest_size);
|
||||
|
||||
int
|
||||
pkcs1_encrypt (size_t key_size,
|
||||
/* For padding */
|
||||
void *random_ctx, nettle_random_func *random,
|
||||
size_t length, const uint8_t *message,
|
||||
mpz_t m);
|
||||
|
||||
int
|
||||
pkcs1_decrypt (size_t key_size,
|
||||
const mpz_t m,
|
||||
size_t *length, uint8_t *message);
|
||||
|
||||
int
|
||||
pkcs1_rsa_digest_encode(mpz_t m, size_t key_size,
|
||||
size_t di_length, const uint8_t *digest_info);
|
||||
|
||||
int
|
||||
pkcs1_rsa_md5_encode(mpz_t m, size_t length, struct md5_ctx *hash);
|
||||
|
||||
int
|
||||
pkcs1_rsa_md5_encode_digest(mpz_t m, size_t length, const uint8_t *digest);
|
||||
|
||||
int
|
||||
pkcs1_rsa_sha1_encode(mpz_t m, size_t length, struct sha1_ctx *hash);
|
||||
|
||||
int
|
||||
pkcs1_rsa_sha1_encode_digest(mpz_t m, size_t length, const uint8_t *digest);
|
||||
|
||||
int
|
||||
pkcs1_rsa_sha256_encode(mpz_t m, size_t length, struct sha256_ctx *hash);
|
||||
|
||||
int
|
||||
pkcs1_rsa_sha256_encode_digest(mpz_t m, size_t length, const uint8_t *digest);
|
||||
|
||||
int
|
||||
pkcs1_rsa_sha512_encode(mpz_t m, size_t length, struct sha512_ctx *hash);
|
||||
|
||||
int
|
||||
pkcs1_rsa_sha512_encode_digest(mpz_t m, size_t length, const uint8_t *digest);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* NETTLE_PKCS1_H_INCLUDED */
|
||||
@@ -1,128 +0,0 @@
|
||||
/* poly1305.h
|
||||
|
||||
Poly1305 message authentication code.
|
||||
|
||||
Copyright (C) 2013 Nikos Mavrogiannopoulos
|
||||
Copyright (C) 2013, 2014 Niels Möller
|
||||
|
||||
This file is part of GNU Nettle.
|
||||
|
||||
GNU Nettle is free software: you can redistribute it and/or
|
||||
modify it under the terms of either:
|
||||
|
||||
* the GNU Lesser General Public License as published by the Free
|
||||
Software Foundation; either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or
|
||||
|
||||
* the GNU General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or both in parallel, as here.
|
||||
|
||||
GNU Nettle is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received copies of the GNU General Public License and
|
||||
the GNU Lesser General Public License along with this program. If
|
||||
not, see http://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
#ifndef NETTLE_POLY1305_H_INCLUDED
|
||||
#define NETTLE_POLY1305_H_INCLUDED
|
||||
|
||||
#include "aes.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Name mangling */
|
||||
#define poly1305_set_key nettle_poly1305_set_key
|
||||
#define poly1305_digest nettle_poly1305_digest
|
||||
#define _poly1305_block _nettle_poly1305_block
|
||||
|
||||
#define poly1305_aes_set_key nettle_poly1305_aes_set_key
|
||||
#define poly1305_aes_set_nonce nettle_poly1305_aes_set_nonce
|
||||
#define poly1305_aes_update nettle_poly1305_aes_update
|
||||
#define poly1305_aes_digest nettle_poly1305_aes_digest
|
||||
|
||||
/* Low level functions/macros for the poly1305 construction. */
|
||||
|
||||
#define POLY1305_DIGEST_SIZE 16
|
||||
#define POLY1305_BLOCK_SIZE 16
|
||||
#define POLY1305_KEY_SIZE 16
|
||||
|
||||
struct poly1305_ctx {
|
||||
/* Key, 128-bit value and some cached multiples. */
|
||||
union
|
||||
{
|
||||
uint32_t r32[6];
|
||||
uint64_t r64[3];
|
||||
} r;
|
||||
uint32_t s32[3];
|
||||
/* State, represented as words of 26, 32 or 64 bits, depending on
|
||||
implementation. */
|
||||
/* High bits first, to maintain alignment. */
|
||||
uint32_t hh;
|
||||
union
|
||||
{
|
||||
uint32_t h32[4];
|
||||
uint64_t h64[2];
|
||||
} h;
|
||||
};
|
||||
|
||||
/* Low-level internal interface. */
|
||||
void poly1305_set_key(struct poly1305_ctx *ctx, const uint8_t key[POLY1305_KEY_SIZE]);
|
||||
/* Extracts digest, and adds it to s, the encrypted nonce. */
|
||||
void poly1305_digest (struct poly1305_ctx *ctx, union nettle_block16 *s);
|
||||
/* Internal function. Process one block. */
|
||||
void _poly1305_block (struct poly1305_ctx *ctx, const uint8_t *m,
|
||||
unsigned high);
|
||||
|
||||
/* poly1305-aes */
|
||||
|
||||
#define POLY1305_AES_KEY_SIZE 32
|
||||
#define POLY1305_AES_DIGEST_SIZE 16
|
||||
#define POLY1305_AES_NONCE_SIZE 16
|
||||
|
||||
struct poly1305_aes_ctx
|
||||
{
|
||||
/* Keep aes context last, to make it possible to use a general
|
||||
poly1305_update if other variants are added. */
|
||||
struct poly1305_ctx pctx;
|
||||
uint8_t block[POLY1305_BLOCK_SIZE];
|
||||
unsigned index;
|
||||
uint8_t nonce[POLY1305_BLOCK_SIZE];
|
||||
struct aes128_ctx aes;
|
||||
};
|
||||
|
||||
/* Also initialize the nonce to zero. */
|
||||
void
|
||||
poly1305_aes_set_key (struct poly1305_aes_ctx *ctx, const uint8_t *key);
|
||||
|
||||
/* Optional, if not used, messages get incrementing nonces starting
|
||||
from zero. */
|
||||
void
|
||||
poly1305_aes_set_nonce (struct poly1305_aes_ctx *ctx,
|
||||
const uint8_t *nonce);
|
||||
|
||||
/* Update is not aes-specific, but since this is the only implemented
|
||||
variant, we need no more general poly1305_update. */
|
||||
void
|
||||
poly1305_aes_update (struct poly1305_aes_ctx *ctx, size_t length, const uint8_t *data);
|
||||
|
||||
/* Also increments the nonce */
|
||||
void
|
||||
poly1305_aes_digest (struct poly1305_aes_ctx *ctx,
|
||||
size_t length, uint8_t *digest);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* NETTLE_POLY1305_H_INCLUDED */
|
||||
@@ -1,58 +0,0 @@
|
||||
/* pss-mgf1.h
|
||||
|
||||
PKCS#1 mask generation function 1, used in RSA-PSS (RFC-3447).
|
||||
|
||||
Copyright (C) 2017 Daiki Ueno
|
||||
|
||||
This file is part of GNU Nettle.
|
||||
|
||||
GNU Nettle is free software: you can redistribute it and/or
|
||||
modify it under the terms of either:
|
||||
|
||||
* the GNU Lesser General Public License as published by the Free
|
||||
Software Foundation; either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or
|
||||
|
||||
* the GNU General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or both in parallel, as here.
|
||||
|
||||
GNU Nettle is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received copies of the GNU General Public License and
|
||||
the GNU Lesser General Public License along with this program. If
|
||||
not, see http://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
#ifndef NETTLE_PSS_MGF1_H_INCLUDED
|
||||
#define NETTLE_PSS_MGF1_H_INCLUDED
|
||||
|
||||
#include "nettle-meta.h"
|
||||
|
||||
#include "sha1.h"
|
||||
#include "sha2.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
/* Namespace mangling */
|
||||
#define pss_mgf1 nettle_pss_mgf1
|
||||
|
||||
void
|
||||
pss_mgf1(const void *seed, const struct nettle_hash *hash,
|
||||
size_t length, uint8_t *mask);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* NETTLE_PSS_MGF1_H_INCLUDED */
|
||||
@@ -1,65 +0,0 @@
|
||||
/* pss.h
|
||||
|
||||
PKCS#1 RSA-PSS (RFC-3447).
|
||||
|
||||
Copyright (C) 2017 Daiki Ueno
|
||||
|
||||
This file is part of GNU Nettle.
|
||||
|
||||
GNU Nettle is free software: you can redistribute it and/or
|
||||
modify it under the terms of either:
|
||||
|
||||
* the GNU Lesser General Public License as published by the Free
|
||||
Software Foundation; either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or
|
||||
|
||||
* the GNU General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or both in parallel, as here.
|
||||
|
||||
GNU Nettle is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received copies of the GNU General Public License and
|
||||
the GNU Lesser General Public License along with this program. If
|
||||
not, see http://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
#ifndef NETTLE_PSS_H_INCLUDED
|
||||
#define NETTLE_PSS_H_INCLUDED
|
||||
|
||||
#include "nettle-types.h"
|
||||
#include "bignum.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
/* Namespace mangling */
|
||||
#define pss_encode_mgf1 nettle_pss_encode_mgf1
|
||||
#define pss_verify_mgf1 nettle_pss_verify_mgf1
|
||||
|
||||
int
|
||||
pss_encode_mgf1(mpz_t m, size_t bits,
|
||||
const struct nettle_hash *hash,
|
||||
size_t salt_length, const uint8_t *salt,
|
||||
const uint8_t *digest);
|
||||
|
||||
int
|
||||
pss_verify_mgf1(const mpz_t m, size_t bits,
|
||||
const struct nettle_hash *hash,
|
||||
size_t salt_length,
|
||||
const uint8_t *digest);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* NETTLE_PSS_H_INCLUDED */
|
||||
@@ -1,48 +0,0 @@
|
||||
/* realloc.h
|
||||
|
||||
Copyright (C) 2002 Niels Möller
|
||||
|
||||
This file is part of GNU Nettle.
|
||||
|
||||
GNU Nettle is free software: you can redistribute it and/or
|
||||
modify it under the terms of either:
|
||||
|
||||
* the GNU Lesser General Public License as published by the Free
|
||||
Software Foundation; either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or
|
||||
|
||||
* the GNU General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or both in parallel, as here.
|
||||
|
||||
GNU Nettle is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received copies of the GNU General Public License and
|
||||
the GNU Lesser General Public License along with this program. If
|
||||
not, see http://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
#ifndef NETTLE_REALLOC_H_INCLUDED
|
||||
#define NETTLE_REALLOC_H_INCLUDED
|
||||
|
||||
#include "nettle-types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
nettle_realloc_func nettle_realloc;
|
||||
nettle_realloc_func nettle_xrealloc;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* NETTLE_REALLOC_H_INCLUDED */
|
||||
@@ -1,88 +0,0 @@
|
||||
/* ripemd160.h
|
||||
|
||||
RIPEMD-160 hash function.
|
||||
|
||||
Copyright (C) 2011 Andres Mejia
|
||||
|
||||
This file is part of GNU Nettle.
|
||||
|
||||
GNU Nettle is free software: you can redistribute it and/or
|
||||
modify it under the terms of either:
|
||||
|
||||
* the GNU Lesser General Public License as published by the Free
|
||||
Software Foundation; either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or
|
||||
|
||||
* the GNU General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or both in parallel, as here.
|
||||
|
||||
GNU Nettle is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received copies of the GNU General Public License and
|
||||
the GNU Lesser General Public License along with this program. If
|
||||
not, see http://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
#ifndef NETTLE_RIPEMD160_H_INCLUDED
|
||||
#define NETTLE_RIPEMD160_H_INCLUDED
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "nettle-types.h"
|
||||
|
||||
/* Name mangling */
|
||||
#define ripemd160_init nettle_ripemd160_init
|
||||
#define ripemd160_update nettle_ripemd160_update
|
||||
#define ripemd160_digest nettle_ripemd160_digest
|
||||
|
||||
/* RIPEMD160 */
|
||||
|
||||
#define RIPEMD160_DIGEST_SIZE 20
|
||||
#define RIPEMD160_BLOCK_SIZE 64
|
||||
/* For backwards compatibility */
|
||||
#define RIPEMD160_DATA_SIZE RIPEMD160_BLOCK_SIZE
|
||||
|
||||
/* Digest is kept internally as 5 32-bit words. */
|
||||
#define _RIPEMD160_DIGEST_LENGTH 5
|
||||
|
||||
struct ripemd160_ctx
|
||||
{
|
||||
uint32_t state[_RIPEMD160_DIGEST_LENGTH];
|
||||
uint64_t count; /* 64-bit block count */
|
||||
uint8_t block[RIPEMD160_BLOCK_SIZE];
|
||||
unsigned int index;
|
||||
};
|
||||
|
||||
void
|
||||
ripemd160_init(struct ripemd160_ctx *ctx);
|
||||
|
||||
void
|
||||
ripemd160_update(struct ripemd160_ctx *ctx,
|
||||
size_t length,
|
||||
const uint8_t *data);
|
||||
|
||||
void
|
||||
ripemd160_digest(struct ripemd160_ctx *ctx,
|
||||
size_t length,
|
||||
uint8_t *digest);
|
||||
|
||||
/* Internal compression function. STATE points to 5 uint32_t words,
|
||||
and DATA points to 64 bytes of input data, possibly unaligned. */
|
||||
void
|
||||
_nettle_ripemd160_compress(uint32_t *state, const uint8_t *data);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* NETTLE_RIPEMD160_H_INCLUDED */
|
||||
@@ -1,564 +0,0 @@
|
||||
/* rsa.h
|
||||
|
||||
The RSA publickey algorithm.
|
||||
|
||||
Copyright (C) 2001, 2002 Niels Möller
|
||||
|
||||
This file is part of GNU Nettle.
|
||||
|
||||
GNU Nettle is free software: you can redistribute it and/or
|
||||
modify it under the terms of either:
|
||||
|
||||
* the GNU Lesser General Public License as published by the Free
|
||||
Software Foundation; either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or
|
||||
|
||||
* the GNU General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or both in parallel, as here.
|
||||
|
||||
GNU Nettle is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received copies of the GNU General Public License and
|
||||
the GNU Lesser General Public License along with this program. If
|
||||
not, see http://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
#ifndef NETTLE_RSA_H_INCLUDED
|
||||
#define NETTLE_RSA_H_INCLUDED
|
||||
|
||||
#include "nettle-types.h"
|
||||
#include "bignum.h"
|
||||
|
||||
#include "md5.h"
|
||||
#include "sha1.h"
|
||||
#include "sha2.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Name mangling */
|
||||
#define rsa_public_key_init nettle_rsa_public_key_init
|
||||
#define rsa_public_key_clear nettle_rsa_public_key_clear
|
||||
#define rsa_public_key_prepare nettle_rsa_public_key_prepare
|
||||
#define rsa_private_key_init nettle_rsa_private_key_init
|
||||
#define rsa_private_key_clear nettle_rsa_private_key_clear
|
||||
#define rsa_private_key_prepare nettle_rsa_private_key_prepare
|
||||
#define rsa_pkcs1_verify nettle_rsa_pkcs1_verify
|
||||
#define rsa_pkcs1_sign nettle_rsa_pkcs1_sign
|
||||
#define rsa_pkcs1_sign_tr nettle_rsa_pkcs1_sign_tr
|
||||
#define rsa_md5_sign nettle_rsa_md5_sign
|
||||
#define rsa_md5_sign_tr nettle_rsa_md5_sign_tr
|
||||
#define rsa_md5_verify nettle_rsa_md5_verify
|
||||
#define rsa_sha1_sign nettle_rsa_sha1_sign
|
||||
#define rsa_sha1_sign_tr nettle_rsa_sha1_sign_tr
|
||||
#define rsa_sha1_verify nettle_rsa_sha1_verify
|
||||
#define rsa_sha256_sign nettle_rsa_sha256_sign
|
||||
#define rsa_sha256_sign_tr nettle_rsa_sha256_sign_tr
|
||||
#define rsa_sha256_verify nettle_rsa_sha256_verify
|
||||
#define rsa_sha512_sign nettle_rsa_sha512_sign
|
||||
#define rsa_sha512_sign_tr nettle_rsa_sha512_sign_tr
|
||||
#define rsa_sha512_verify nettle_rsa_sha512_verify
|
||||
#define rsa_md5_sign_digest nettle_rsa_md5_sign_digest
|
||||
#define rsa_md5_sign_digest_tr nettle_rsa_md5_sign_digest_tr
|
||||
#define rsa_md5_verify_digest nettle_rsa_md5_verify_digest
|
||||
#define rsa_sha1_sign_digest nettle_rsa_sha1_sign_digest
|
||||
#define rsa_sha1_sign_digest_tr nettle_rsa_sha1_sign_digest_tr
|
||||
#define rsa_sha1_verify_digest nettle_rsa_sha1_verify_digest
|
||||
#define rsa_sha256_sign_digest nettle_rsa_sha256_sign_digest
|
||||
#define rsa_sha256_sign_digest_tr nettle_rsa_sha256_sign_digest_tr
|
||||
#define rsa_sha256_verify_digest nettle_rsa_sha256_verify_digest
|
||||
#define rsa_sha512_sign_digest nettle_rsa_sha512_sign_digest
|
||||
#define rsa_sha512_sign_digest_tr nettle_rsa_sha512_sign_digest_tr
|
||||
#define rsa_sha512_verify_digest nettle_rsa_sha512_verify_digest
|
||||
#define rsa_pss_sha256_sign_digest_tr nettle_rsa_pss_sha256_sign_digest_tr
|
||||
#define rsa_pss_sha256_verify_digest nettle_rsa_pss_sha256_verify_digest
|
||||
#define rsa_pss_sha384_sign_digest_tr nettle_rsa_pss_sha384_sign_digest_tr
|
||||
#define rsa_pss_sha384_verify_digest nettle_rsa_pss_sha384_verify_digest
|
||||
#define rsa_pss_sha512_sign_digest_tr nettle_rsa_pss_sha512_sign_digest_tr
|
||||
#define rsa_pss_sha512_verify_digest nettle_rsa_pss_sha512_verify_digest
|
||||
#define rsa_encrypt nettle_rsa_encrypt
|
||||
#define rsa_decrypt nettle_rsa_decrypt
|
||||
#define rsa_decrypt_tr nettle_rsa_decrypt_tr
|
||||
#define rsa_sec_decrypt nettle_rsa_sec_decrypt
|
||||
#define rsa_compute_root nettle_rsa_compute_root
|
||||
#define rsa_compute_root_tr nettle_rsa_compute_root_tr
|
||||
#define rsa_generate_keypair nettle_rsa_generate_keypair
|
||||
#define rsa_keypair_to_sexp nettle_rsa_keypair_to_sexp
|
||||
#define rsa_keypair_from_sexp_alist nettle_rsa_keypair_from_sexp_alist
|
||||
#define rsa_keypair_from_sexp nettle_rsa_keypair_from_sexp
|
||||
#define rsa_public_key_from_der_iterator nettle_rsa_public_key_from_der_iterator
|
||||
#define rsa_private_key_from_der_iterator nettle_rsa_private_key_from_der_iterator
|
||||
#define rsa_keypair_from_der nettle_rsa_keypair_from_der
|
||||
#define rsa_keypair_to_openpgp nettle_rsa_keypair_to_openpgp
|
||||
#define _rsa_verify _nettle_rsa_verify
|
||||
#define _rsa_verify_recover _nettle_rsa_verify_recover
|
||||
#define _rsa_check_size _nettle_rsa_check_size
|
||||
#define _rsa_blind _nettle_rsa_blind
|
||||
#define _rsa_unblind _nettle_rsa_unblind
|
||||
|
||||
/* This limit is somewhat arbitrary. Technically, the smallest modulo
|
||||
which makes sense at all is 15 = 3*5, phi(15) = 8, size 4 bits. But
|
||||
for ridiculously small keys, not all odd e are possible (e.g., for
|
||||
5 bits, the only possible modulo is 3*7 = 21, phi(21) = 12, and e =
|
||||
3 don't work). The smallest size that makes sense with pkcs#1, and
|
||||
which allows RSA encryption of one byte messages, is 12 octets, 89
|
||||
bits. */
|
||||
|
||||
#define RSA_MINIMUM_N_OCTETS 12
|
||||
#define RSA_MINIMUM_N_BITS (8*RSA_MINIMUM_N_OCTETS - 7)
|
||||
|
||||
struct rsa_public_key
|
||||
{
|
||||
/* Size of the modulo, in octets. This is also the size of all
|
||||
* signatures that are created or verified with this key. */
|
||||
size_t size;
|
||||
|
||||
/* Modulo */
|
||||
mpz_t n;
|
||||
|
||||
/* Public exponent */
|
||||
mpz_t e;
|
||||
};
|
||||
|
||||
struct rsa_private_key
|
||||
{
|
||||
size_t size;
|
||||
|
||||
/* d is filled in by the key generation function; otherwise it's
|
||||
* completely unused. */
|
||||
mpz_t d;
|
||||
|
||||
/* The two factors */
|
||||
mpz_t p; mpz_t q;
|
||||
|
||||
/* d % (p-1), i.e. a e = 1 (mod (p-1)) */
|
||||
mpz_t a;
|
||||
|
||||
/* d % (q-1), i.e. b e = 1 (mod (q-1)) */
|
||||
mpz_t b;
|
||||
|
||||
/* modular inverse of q , i.e. c q = 1 (mod p) */
|
||||
mpz_t c;
|
||||
};
|
||||
|
||||
/* Signing a message works as follows:
|
||||
*
|
||||
* Store the private key in a rsa_private_key struct.
|
||||
*
|
||||
* Call rsa_private_key_prepare. This initializes the size attribute
|
||||
* to the length of a signature.
|
||||
*
|
||||
* Initialize a hashing context, by callling
|
||||
* md5_init
|
||||
*
|
||||
* Hash the message by calling
|
||||
* md5_update
|
||||
*
|
||||
* Create the signature by calling
|
||||
* rsa_md5_sign
|
||||
*
|
||||
* The signature is represented as a mpz_t bignum. This call also
|
||||
* resets the hashing context.
|
||||
*
|
||||
* When done with the key and signature, don't forget to call
|
||||
* mpz_clear.
|
||||
*/
|
||||
|
||||
/* Calls mpz_init to initialize bignum storage. */
|
||||
void
|
||||
rsa_public_key_init(struct rsa_public_key *key);
|
||||
|
||||
/* Calls mpz_clear to deallocate bignum storage. */
|
||||
void
|
||||
rsa_public_key_clear(struct rsa_public_key *key);
|
||||
|
||||
int
|
||||
rsa_public_key_prepare(struct rsa_public_key *key);
|
||||
|
||||
/* Calls mpz_init to initialize bignum storage. */
|
||||
void
|
||||
rsa_private_key_init(struct rsa_private_key *key);
|
||||
|
||||
/* Calls mpz_clear to deallocate bignum storage. */
|
||||
void
|
||||
rsa_private_key_clear(struct rsa_private_key *key);
|
||||
|
||||
int
|
||||
rsa_private_key_prepare(struct rsa_private_key *key);
|
||||
|
||||
|
||||
/* PKCS#1 style signatures */
|
||||
int
|
||||
rsa_pkcs1_sign(const struct rsa_private_key *key,
|
||||
size_t length, const uint8_t *digest_info,
|
||||
mpz_t s);
|
||||
|
||||
int
|
||||
rsa_pkcs1_sign_tr(const struct rsa_public_key *pub,
|
||||
const struct rsa_private_key *key,
|
||||
void *random_ctx, nettle_random_func *random,
|
||||
size_t length, const uint8_t *digest_info,
|
||||
mpz_t s);
|
||||
int
|
||||
rsa_pkcs1_verify(const struct rsa_public_key *key,
|
||||
size_t length, const uint8_t *digest_info,
|
||||
const mpz_t signature);
|
||||
|
||||
int
|
||||
rsa_md5_sign(const struct rsa_private_key *key,
|
||||
struct md5_ctx *hash,
|
||||
mpz_t signature);
|
||||
|
||||
int
|
||||
rsa_md5_sign_tr(const struct rsa_public_key *pub,
|
||||
const struct rsa_private_key *key,
|
||||
void *random_ctx, nettle_random_func *random,
|
||||
struct md5_ctx *hash, mpz_t s);
|
||||
|
||||
|
||||
int
|
||||
rsa_md5_verify(const struct rsa_public_key *key,
|
||||
struct md5_ctx *hash,
|
||||
const mpz_t signature);
|
||||
|
||||
int
|
||||
rsa_sha1_sign(const struct rsa_private_key *key,
|
||||
struct sha1_ctx *hash,
|
||||
mpz_t signature);
|
||||
|
||||
int
|
||||
rsa_sha1_sign_tr(const struct rsa_public_key *pub,
|
||||
const struct rsa_private_key *key,
|
||||
void *random_ctx, nettle_random_func *random,
|
||||
struct sha1_ctx *hash,
|
||||
mpz_t s);
|
||||
|
||||
int
|
||||
rsa_sha1_verify(const struct rsa_public_key *key,
|
||||
struct sha1_ctx *hash,
|
||||
const mpz_t signature);
|
||||
|
||||
int
|
||||
rsa_sha256_sign(const struct rsa_private_key *key,
|
||||
struct sha256_ctx *hash,
|
||||
mpz_t signature);
|
||||
|
||||
int
|
||||
rsa_sha256_sign_tr(const struct rsa_public_key *pub,
|
||||
const struct rsa_private_key *key,
|
||||
void *random_ctx, nettle_random_func *random,
|
||||
struct sha256_ctx *hash,
|
||||
mpz_t s);
|
||||
|
||||
int
|
||||
rsa_sha256_verify(const struct rsa_public_key *key,
|
||||
struct sha256_ctx *hash,
|
||||
const mpz_t signature);
|
||||
|
||||
int
|
||||
rsa_sha512_sign(const struct rsa_private_key *key,
|
||||
struct sha512_ctx *hash,
|
||||
mpz_t signature);
|
||||
|
||||
int
|
||||
rsa_sha512_sign_tr(const struct rsa_public_key *pub,
|
||||
const struct rsa_private_key *key,
|
||||
void *random_ctx, nettle_random_func *random,
|
||||
struct sha512_ctx *hash,
|
||||
mpz_t s);
|
||||
|
||||
int
|
||||
rsa_sha512_verify(const struct rsa_public_key *key,
|
||||
struct sha512_ctx *hash,
|
||||
const mpz_t signature);
|
||||
|
||||
/* Variants taking the digest as argument. */
|
||||
int
|
||||
rsa_md5_sign_digest(const struct rsa_private_key *key,
|
||||
const uint8_t *digest,
|
||||
mpz_t s);
|
||||
|
||||
int
|
||||
rsa_md5_sign_digest_tr(const struct rsa_public_key *pub,
|
||||
const struct rsa_private_key *key,
|
||||
void *random_ctx, nettle_random_func *random,
|
||||
const uint8_t *digest, mpz_t s);
|
||||
|
||||
int
|
||||
rsa_md5_verify_digest(const struct rsa_public_key *key,
|
||||
const uint8_t *digest,
|
||||
const mpz_t signature);
|
||||
|
||||
int
|
||||
rsa_sha1_sign_digest(const struct rsa_private_key *key,
|
||||
const uint8_t *digest,
|
||||
mpz_t s);
|
||||
|
||||
int
|
||||
rsa_sha1_sign_digest_tr(const struct rsa_public_key *pub,
|
||||
const struct rsa_private_key *key,
|
||||
void *random_ctx, nettle_random_func *random,
|
||||
const uint8_t *digest,
|
||||
mpz_t s);
|
||||
|
||||
int
|
||||
rsa_sha1_verify_digest(const struct rsa_public_key *key,
|
||||
const uint8_t *digest,
|
||||
const mpz_t signature);
|
||||
|
||||
int
|
||||
rsa_sha256_sign_digest(const struct rsa_private_key *key,
|
||||
const uint8_t *digest,
|
||||
mpz_t s);
|
||||
|
||||
int
|
||||
rsa_sha256_sign_digest_tr(const struct rsa_public_key *pub,
|
||||
const struct rsa_private_key *key,
|
||||
void *random_ctx, nettle_random_func *random,
|
||||
const uint8_t *digest,
|
||||
mpz_t s);
|
||||
|
||||
int
|
||||
rsa_sha256_verify_digest(const struct rsa_public_key *key,
|
||||
const uint8_t *digest,
|
||||
const mpz_t signature);
|
||||
|
||||
int
|
||||
rsa_sha512_sign_digest(const struct rsa_private_key *key,
|
||||
const uint8_t *digest,
|
||||
mpz_t s);
|
||||
|
||||
int
|
||||
rsa_sha512_sign_digest_tr(const struct rsa_public_key *pub,
|
||||
const struct rsa_private_key *key,
|
||||
void *random_ctx, nettle_random_func *random,
|
||||
const uint8_t *digest,
|
||||
mpz_t s);
|
||||
|
||||
int
|
||||
rsa_sha512_verify_digest(const struct rsa_public_key *key,
|
||||
const uint8_t *digest,
|
||||
const mpz_t signature);
|
||||
|
||||
/* PSS style signatures */
|
||||
int
|
||||
rsa_pss_sha256_sign_digest_tr(const struct rsa_public_key *pub,
|
||||
const struct rsa_private_key *key,
|
||||
void *random_ctx, nettle_random_func *random,
|
||||
size_t salt_length, const uint8_t *salt,
|
||||
const uint8_t *digest,
|
||||
mpz_t s);
|
||||
|
||||
int
|
||||
rsa_pss_sha256_verify_digest(const struct rsa_public_key *key,
|
||||
size_t salt_length,
|
||||
const uint8_t *digest,
|
||||
const mpz_t signature);
|
||||
|
||||
int
|
||||
rsa_pss_sha384_sign_digest_tr(const struct rsa_public_key *pub,
|
||||
const struct rsa_private_key *key,
|
||||
void *random_ctx, nettle_random_func *random,
|
||||
size_t salt_length, const uint8_t *salt,
|
||||
const uint8_t *digest,
|
||||
mpz_t s);
|
||||
|
||||
int
|
||||
rsa_pss_sha384_verify_digest(const struct rsa_public_key *key,
|
||||
size_t salt_length,
|
||||
const uint8_t *digest,
|
||||
const mpz_t signature);
|
||||
|
||||
int
|
||||
rsa_pss_sha512_sign_digest_tr(const struct rsa_public_key *pub,
|
||||
const struct rsa_private_key *key,
|
||||
void *random_ctx, nettle_random_func *random,
|
||||
size_t salt_length, const uint8_t *salt,
|
||||
const uint8_t *digest,
|
||||
mpz_t s);
|
||||
|
||||
int
|
||||
rsa_pss_sha512_verify_digest(const struct rsa_public_key *key,
|
||||
size_t salt_length,
|
||||
const uint8_t *digest,
|
||||
const mpz_t signature);
|
||||
|
||||
|
||||
/* RSA encryption, using PKCS#1 */
|
||||
/* These functions uses the v1.5 padding. What should the v2 (OAEP)
|
||||
* functions be called? */
|
||||
|
||||
/* Returns 1 on success, 0 on failure, which happens if the
|
||||
* message is too long for the key. */
|
||||
int
|
||||
rsa_encrypt(const struct rsa_public_key *key,
|
||||
/* For padding */
|
||||
void *random_ctx, nettle_random_func *random,
|
||||
size_t length, const uint8_t *cleartext,
|
||||
mpz_t cipher);
|
||||
|
||||
/* Message must point to a buffer of size *LENGTH. KEY->size is enough
|
||||
* for all valid messages. On success, *LENGTH is updated to reflect
|
||||
* the actual length of the message. Returns 1 on success, 0 on
|
||||
* failure, which happens if decryption failed or if the message
|
||||
* didn't fit. */
|
||||
int
|
||||
rsa_decrypt(const struct rsa_private_key *key,
|
||||
size_t *length, uint8_t *cleartext,
|
||||
const mpz_t ciphertext);
|
||||
|
||||
/* Timing-resistant version, using randomized RSA blinding. */
|
||||
int
|
||||
rsa_decrypt_tr(const struct rsa_public_key *pub,
|
||||
const struct rsa_private_key *key,
|
||||
void *random_ctx, nettle_random_func *random,
|
||||
size_t *length, uint8_t *message,
|
||||
const mpz_t gibberish);
|
||||
|
||||
/* like rsa_decrypt_tr but with additional side-channel resistance.
|
||||
* NOTE: the length of the final message must be known in advance. */
|
||||
int
|
||||
rsa_sec_decrypt(const struct rsa_public_key *pub,
|
||||
const struct rsa_private_key *key,
|
||||
void *random_ctx, nettle_random_func *random,
|
||||
size_t length, uint8_t *message,
|
||||
const mpz_t gibberish);
|
||||
|
||||
/* Compute x, the e:th root of m. Calling it with x == m is allowed. */
|
||||
void
|
||||
rsa_compute_root(const struct rsa_private_key *key,
|
||||
mpz_t x, const mpz_t m);
|
||||
|
||||
/* Safer variant, using RSA blinding, and checking the result after
|
||||
CRT. */
|
||||
int
|
||||
rsa_compute_root_tr(const struct rsa_public_key *pub,
|
||||
const struct rsa_private_key *key,
|
||||
void *random_ctx, nettle_random_func *random,
|
||||
mpz_t x, const mpz_t m);
|
||||
|
||||
/* Key generation */
|
||||
|
||||
/* Note that the key structs must be initialized first. */
|
||||
int
|
||||
rsa_generate_keypair(struct rsa_public_key *pub,
|
||||
struct rsa_private_key *key,
|
||||
|
||||
void *random_ctx, nettle_random_func *random,
|
||||
void *progress_ctx, nettle_progress_func *progress,
|
||||
|
||||
/* Desired size of modulo, in bits */
|
||||
unsigned n_size,
|
||||
|
||||
/* Desired size of public exponent, in bits. If
|
||||
* zero, the passed in value pub->e is used. */
|
||||
unsigned e_size);
|
||||
|
||||
|
||||
#define RSA_SIGN(key, algorithm, ctx, length, data, signature) ( \
|
||||
algorithm##_update(ctx, length, data), \
|
||||
rsa_##algorithm##_sign(key, ctx, signature) \
|
||||
)
|
||||
|
||||
#define RSA_VERIFY(key, algorithm, ctx, length, data, signature) ( \
|
||||
algorithm##_update(ctx, length, data), \
|
||||
rsa_##algorithm##_verify(key, ctx, signature) \
|
||||
)
|
||||
|
||||
|
||||
/* Keys in sexp form. */
|
||||
|
||||
struct nettle_buffer;
|
||||
|
||||
/* Generates a public-key expression if PRIV is NULL .*/
|
||||
int
|
||||
rsa_keypair_to_sexp(struct nettle_buffer *buffer,
|
||||
const char *algorithm_name, /* NULL means "rsa" */
|
||||
const struct rsa_public_key *pub,
|
||||
const struct rsa_private_key *priv);
|
||||
|
||||
struct sexp_iterator;
|
||||
|
||||
int
|
||||
rsa_keypair_from_sexp_alist(struct rsa_public_key *pub,
|
||||
struct rsa_private_key *priv,
|
||||
unsigned limit,
|
||||
struct sexp_iterator *i);
|
||||
|
||||
/* If PRIV is NULL, expect a public-key expression. If PUB is NULL,
|
||||
* expect a private key expression and ignore the parts not needed for
|
||||
* the public key. */
|
||||
/* Keys must be initialized before calling this function, as usual. */
|
||||
int
|
||||
rsa_keypair_from_sexp(struct rsa_public_key *pub,
|
||||
struct rsa_private_key *priv,
|
||||
unsigned limit,
|
||||
size_t length, const uint8_t *expr);
|
||||
|
||||
|
||||
/* Keys in PKCS#1 format. */
|
||||
struct asn1_der_iterator;
|
||||
|
||||
int
|
||||
rsa_public_key_from_der_iterator(struct rsa_public_key *pub,
|
||||
unsigned limit,
|
||||
struct asn1_der_iterator *i);
|
||||
|
||||
int
|
||||
rsa_private_key_from_der_iterator(struct rsa_public_key *pub,
|
||||
struct rsa_private_key *priv,
|
||||
unsigned limit,
|
||||
struct asn1_der_iterator *i);
|
||||
|
||||
/* For public keys, use PRIV == NULL */
|
||||
int
|
||||
rsa_keypair_from_der(struct rsa_public_key *pub,
|
||||
struct rsa_private_key *priv,
|
||||
unsigned limit,
|
||||
size_t length, const uint8_t *data);
|
||||
|
||||
/* OpenPGP format. Experimental interface, subject to change. */
|
||||
int
|
||||
rsa_keypair_to_openpgp(struct nettle_buffer *buffer,
|
||||
const struct rsa_public_key *pub,
|
||||
const struct rsa_private_key *priv,
|
||||
/* A single user id. NUL-terminated utf8. */
|
||||
const char *userid);
|
||||
|
||||
/* Internal functions. */
|
||||
int
|
||||
_rsa_verify(const struct rsa_public_key *key,
|
||||
const mpz_t m,
|
||||
const mpz_t s);
|
||||
|
||||
int
|
||||
_rsa_verify_recover(const struct rsa_public_key *key,
|
||||
mpz_t m,
|
||||
const mpz_t s);
|
||||
|
||||
size_t
|
||||
_rsa_check_size(mpz_t n);
|
||||
|
||||
/* _rsa_blind and _rsa_unblind are deprecated, unused in the library,
|
||||
and will likely be removed with the next ABI break. */
|
||||
void
|
||||
_rsa_blind (const struct rsa_public_key *pub,
|
||||
void *random_ctx, nettle_random_func *random,
|
||||
mpz_t c, mpz_t ri);
|
||||
void
|
||||
_rsa_unblind (const struct rsa_public_key *pub, mpz_t c, const mpz_t ri);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* NETTLE_RSA_H_INCLUDED */
|
||||
@@ -1,114 +0,0 @@
|
||||
/* salsa20.h
|
||||
|
||||
The Salsa20 stream cipher.
|
||||
|
||||
Copyright (C) 2012 Simon Josefsson
|
||||
Copyright (C) 2001 Niels Möller
|
||||
|
||||
This file is part of GNU Nettle.
|
||||
|
||||
GNU Nettle is free software: you can redistribute it and/or
|
||||
modify it under the terms of either:
|
||||
|
||||
* the GNU Lesser General Public License as published by the Free
|
||||
Software Foundation; either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or
|
||||
|
||||
* the GNU General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or both in parallel, as here.
|
||||
|
||||
GNU Nettle is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received copies of the GNU General Public License and
|
||||
the GNU Lesser General Public License along with this program. If
|
||||
not, see http://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
#ifndef NETTLE_SALSA20_H_INCLUDED
|
||||
#define NETTLE_SALSA20_H_INCLUDED
|
||||
|
||||
#include "nettle-types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Name mangling */
|
||||
#define salsa20_set_key nettle_salsa20_set_key
|
||||
#define salsa20_128_set_key nettle_salsa20_128_set_key
|
||||
#define salsa20_256_set_key nettle_salsa20_256_set_key
|
||||
#define salsa20_set_nonce nettle_salsa20_set_nonce
|
||||
#define salsa20_crypt nettle_salsa20_crypt
|
||||
#define _salsa20_core _nettle_salsa20_core
|
||||
|
||||
#define salsa20r12_crypt nettle_salsa20r12_crypt
|
||||
|
||||
/* Alias for backwards compatibility */
|
||||
#define salsa20_set_iv nettle_salsa20_set_nonce
|
||||
|
||||
/* In octets.*/
|
||||
#define SALSA20_128_KEY_SIZE 16
|
||||
#define SALSA20_256_KEY_SIZE 32
|
||||
#define SALSA20_BLOCK_SIZE 64
|
||||
#define SALSA20_NONCE_SIZE 8
|
||||
#define SALSA20_IV_SIZE SALSA20_NONCE_SIZE
|
||||
|
||||
/* Aliases */
|
||||
#define SALSA20_MIN_KEY_SIZE 16
|
||||
#define SALSA20_MAX_KEY_SIZE 32
|
||||
#define SALSA20_KEY_SIZE 32
|
||||
|
||||
#define _SALSA20_INPUT_LENGTH 16
|
||||
|
||||
struct salsa20_ctx
|
||||
{
|
||||
/* Indices 1-4 and 11-14 holds the key (two identical copies for the
|
||||
shorter key size), indices 0, 5, 10, 15 are constant, indices 6, 7
|
||||
are the IV, and indices 8, 9 are the block counter:
|
||||
|
||||
C K K K
|
||||
K C I I
|
||||
B B C K
|
||||
K K K C
|
||||
*/
|
||||
uint32_t input[_SALSA20_INPUT_LENGTH];
|
||||
};
|
||||
|
||||
void
|
||||
salsa20_128_set_key(struct salsa20_ctx *ctx, const uint8_t *key);
|
||||
void
|
||||
salsa20_256_set_key(struct salsa20_ctx *ctx, const uint8_t *key);
|
||||
|
||||
void
|
||||
salsa20_set_key(struct salsa20_ctx *ctx,
|
||||
size_t length, const uint8_t *key);
|
||||
|
||||
void
|
||||
salsa20_set_nonce(struct salsa20_ctx *ctx, const uint8_t *nonce);
|
||||
|
||||
void
|
||||
salsa20_crypt(struct salsa20_ctx *ctx,
|
||||
size_t length, uint8_t *dst,
|
||||
const uint8_t *src);
|
||||
|
||||
void
|
||||
salsa20r12_crypt(struct salsa20_ctx *ctx,
|
||||
size_t length, uint8_t *dst,
|
||||
const uint8_t *src);
|
||||
|
||||
void
|
||||
_salsa20_core(uint32_t *dst, const uint32_t *src, unsigned rounds);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* NETTLE_SALSA20_H_INCLUDED */
|
||||
@@ -1,102 +0,0 @@
|
||||
/* serpent.h
|
||||
|
||||
The serpent block cipher.
|
||||
|
||||
Copyright (C) 2001 Niels Möller
|
||||
|
||||
This file is part of GNU Nettle.
|
||||
|
||||
GNU Nettle is free software: you can redistribute it and/or
|
||||
modify it under the terms of either:
|
||||
|
||||
* the GNU Lesser General Public License as published by the Free
|
||||
Software Foundation; either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or
|
||||
|
||||
* the GNU General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or both in parallel, as here.
|
||||
|
||||
GNU Nettle is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received copies of the GNU General Public License and
|
||||
the GNU Lesser General Public License along with this program. If
|
||||
not, see http://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
/* Serpent is a 128-bit block cipher that accepts a key size of 256
|
||||
* bits, designed by Ross Anderson, Eli Biham, and Lars Knudsen. See
|
||||
* http://www.cl.cam.ac.uk/~rja14/serpent.html for details.
|
||||
*/
|
||||
|
||||
#ifndef NETTLE_SERPENT_H_INCLUDED
|
||||
#define NETTLE_SERPENT_H_INCLUDED
|
||||
|
||||
#include "nettle-types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Name mangling */
|
||||
#define serpent_set_key nettle_serpent_set_key
|
||||
#define serpent128_set_key nettle_serpent128_set_key
|
||||
#define serpent192_set_key nettle_serpent192_set_key
|
||||
#define serpent256_set_key nettle_serpent256_set_key
|
||||
#define serpent_encrypt nettle_serpent_encrypt
|
||||
#define serpent_decrypt nettle_serpent_decrypt
|
||||
|
||||
#define SERPENT_BLOCK_SIZE 16
|
||||
|
||||
/* Other key lengths are possible, but the design of Serpent makes
|
||||
* smaller key lengths quite pointless; they cheated with the AES
|
||||
* requirements, using a 256-bit key length exclusively and just
|
||||
* padding it out if the desired key length was less, so there really
|
||||
* is no advantage to using key lengths less than 256 bits. */
|
||||
#define SERPENT_KEY_SIZE 32
|
||||
|
||||
/* Allow keys of size 128 <= bits <= 256 */
|
||||
|
||||
#define SERPENT_MIN_KEY_SIZE 16
|
||||
#define SERPENT_MAX_KEY_SIZE 32
|
||||
|
||||
#define SERPENT128_KEY_SIZE 16
|
||||
#define SERPENT192_KEY_SIZE 24
|
||||
#define SERPENT256_KEY_SIZE 32
|
||||
|
||||
struct serpent_ctx
|
||||
{
|
||||
uint32_t keys[33][4]; /* key schedule */
|
||||
};
|
||||
|
||||
void
|
||||
serpent_set_key(struct serpent_ctx *ctx,
|
||||
size_t length, const uint8_t *key);
|
||||
void
|
||||
serpent128_set_key(struct serpent_ctx *ctx, const uint8_t *key);
|
||||
void
|
||||
serpent192_set_key(struct serpent_ctx *ctx, const uint8_t *key);
|
||||
void
|
||||
serpent256_set_key(struct serpent_ctx *ctx, const uint8_t *key);
|
||||
|
||||
void
|
||||
serpent_encrypt(const struct serpent_ctx *ctx,
|
||||
size_t length, uint8_t *dst,
|
||||
const uint8_t *src);
|
||||
void
|
||||
serpent_decrypt(const struct serpent_ctx *ctx,
|
||||
size_t length, uint8_t *dst,
|
||||
const uint8_t *src);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* NETTLE_SERPENT_H_INCLUDED */
|
||||
@@ -1,213 +0,0 @@
|
||||
/* sexp.h
|
||||
|
||||
Parsing s-expressions.
|
||||
Copyright (C) 2002 Niels Möller
|
||||
|
||||
This file is part of GNU Nettle.
|
||||
|
||||
GNU Nettle is free software: you can redistribute it and/or
|
||||
modify it under the terms of either:
|
||||
|
||||
* the GNU Lesser General Public License as published by the Free
|
||||
Software Foundation; either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or
|
||||
|
||||
* the GNU General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or both in parallel, as here.
|
||||
|
||||
GNU Nettle is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received copies of the GNU General Public License and
|
||||
the GNU Lesser General Public License along with this program. If
|
||||
not, see http://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
#ifndef NETTLE_SEXP_H_INCLUDED
|
||||
#define NETTLE_SEXP_H_INCLUDED
|
||||
|
||||
#include <stdarg.h>
|
||||
#include "nettle-types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Name mangling */
|
||||
#define sexp_iterator_first nettle_sexp_iterator_first
|
||||
#define sexp_transport_iterator_first nettle_sexp_transport_iterator_first
|
||||
#define sexp_iterator_next nettle_sexp_iterator_next
|
||||
#define sexp_iterator_enter_list nettle_sexp_iterator_enter_list
|
||||
#define sexp_iterator_exit_list nettle_sexp_iterator_exit_list
|
||||
#define sexp_iterator_subexpr nettle_sexp_iterator_subexpr
|
||||
#define sexp_iterator_get_uint32 nettle_sexp_iterator_get_uint32
|
||||
#define sexp_iterator_check_type nettle_sexp_iterator_check_type
|
||||
#define sexp_iterator_check_types nettle_sexp_iterator_check_types
|
||||
#define sexp_iterator_assoc nettle_sexp_iterator_assoc
|
||||
#define sexp_format nettle_sexp_format
|
||||
#define sexp_vformat nettle_sexp_vformat
|
||||
#define sexp_transport_format nettle_sexp_transport_format
|
||||
#define sexp_transport_vformat nettle_sexp_transport_vformat
|
||||
#define sexp_token_chars nettle_sexp_token_chars
|
||||
|
||||
enum sexp_type
|
||||
{ SEXP_ATOM, SEXP_LIST, SEXP_END };
|
||||
|
||||
struct sexp_iterator
|
||||
{
|
||||
size_t length;
|
||||
const uint8_t *buffer;
|
||||
|
||||
/* Points at the start of the current sub expression. */
|
||||
size_t start;
|
||||
/* If type is SEXP_LIST, pos points at the start of the current
|
||||
* element. Otherwise, it points at the end. */
|
||||
size_t pos;
|
||||
unsigned level;
|
||||
|
||||
enum sexp_type type;
|
||||
|
||||
size_t display_length;
|
||||
const uint8_t *display;
|
||||
|
||||
size_t atom_length;
|
||||
const uint8_t *atom;
|
||||
};
|
||||
|
||||
|
||||
/* All these functions return 1 on success, 0 on failure */
|
||||
|
||||
/* Initializes the iterator. */
|
||||
int
|
||||
sexp_iterator_first(struct sexp_iterator *iterator,
|
||||
size_t length, const uint8_t *input);
|
||||
|
||||
/* NOTE: Decodes the input string in place */
|
||||
int
|
||||
sexp_transport_iterator_first(struct sexp_iterator *iterator,
|
||||
size_t length, uint8_t *input);
|
||||
|
||||
int
|
||||
sexp_iterator_next(struct sexp_iterator *iterator);
|
||||
|
||||
/* Current element must be a list. */
|
||||
int
|
||||
sexp_iterator_enter_list(struct sexp_iterator *iterator);
|
||||
|
||||
/* Skips the rest of the current list */
|
||||
int
|
||||
sexp_iterator_exit_list(struct sexp_iterator *iterator);
|
||||
|
||||
#if 0
|
||||
/* Skips out of as many lists as necessary to get back to the given
|
||||
* level. */
|
||||
int
|
||||
sexp_iterator_exit_lists(struct sexp_iterator *iterator,
|
||||
unsigned level);
|
||||
#endif
|
||||
|
||||
/* Gets start and length of the current subexpression. Implies
|
||||
* sexp_iterator_next. */
|
||||
const uint8_t *
|
||||
sexp_iterator_subexpr(struct sexp_iterator *iterator,
|
||||
size_t *length);
|
||||
|
||||
int
|
||||
sexp_iterator_get_uint32(struct sexp_iterator *iterator,
|
||||
uint32_t *x);
|
||||
|
||||
|
||||
/* Checks the type of the current expression, which should be a list
|
||||
*
|
||||
* (<type> ...)
|
||||
*/
|
||||
int
|
||||
sexp_iterator_check_type(struct sexp_iterator *iterator,
|
||||
const char *type);
|
||||
|
||||
const char *
|
||||
sexp_iterator_check_types(struct sexp_iterator *iterator,
|
||||
unsigned ntypes,
|
||||
const char * const *types);
|
||||
|
||||
/* Current element must be a list. Looks up element of type
|
||||
*
|
||||
* (key rest...)
|
||||
*
|
||||
* For a matching key, the corresponding iterator is initialized
|
||||
* pointing at the start of REST.
|
||||
*
|
||||
* On success, exits the current list.
|
||||
*/
|
||||
int
|
||||
sexp_iterator_assoc(struct sexp_iterator *iterator,
|
||||
unsigned nkeys,
|
||||
const char * const *keys,
|
||||
struct sexp_iterator *values);
|
||||
|
||||
|
||||
/* Output functions. What is a reasonable API for this? It seems
|
||||
* ugly to have to reimplement string streams. */
|
||||
|
||||
/* Declared for real in buffer.h */
|
||||
struct nettle_buffer;
|
||||
|
||||
/* Returns the number of output characters, or 0 on out of memory. If
|
||||
* buffer == NULL, just compute length.
|
||||
*
|
||||
* Format strings can contained matched parentheses, tokens ("foo" in
|
||||
* the format string is formatted as "3:foo"), whitespace (which
|
||||
* separates tokens but is otherwise ignored) and the following
|
||||
* formatting specifiers:
|
||||
*
|
||||
* %s String represented as size_t length, const uint8_t *data.
|
||||
*
|
||||
* %t Optional display type, represented as
|
||||
* size_t display_length, const uint8_t *display,
|
||||
* display == NULL means no display type.
|
||||
*
|
||||
* %i Non-negative small integer, uint32_t.
|
||||
*
|
||||
* %b Non-negative bignum, mpz_t.
|
||||
*
|
||||
* %l Literal string (no length added), typically a balanced
|
||||
* subexpression. Represented as size_t length, const uint8_t
|
||||
* *data.
|
||||
*
|
||||
* %(, %) Allows insertion of unbalanced parenthesis.
|
||||
*
|
||||
* Modifiers:
|
||||
*
|
||||
* %0 For %s, %t and %l, says that there's no length argument,
|
||||
* instead the string is NUL-terminated, and there's only one
|
||||
* const uint8_t * argument.
|
||||
*/
|
||||
|
||||
size_t
|
||||
sexp_format(struct nettle_buffer *buffer,
|
||||
const char *format, ...);
|
||||
|
||||
size_t
|
||||
sexp_vformat(struct nettle_buffer *buffer,
|
||||
const char *format, va_list args);
|
||||
|
||||
size_t
|
||||
sexp_transport_format(struct nettle_buffer *buffer,
|
||||
const char *format, ...);
|
||||
|
||||
size_t
|
||||
sexp_transport_vformat(struct nettle_buffer *buffer,
|
||||
const char *format, va_list args);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* NETTLE_SEXP_H_INCLUDED */
|
||||
@@ -1,42 +0,0 @@
|
||||
/* sha.h
|
||||
|
||||
This file is deprecated, and provided only for backwards
|
||||
compatibility with earlier versions of Nettle. Please use sha1.h
|
||||
and/or sha2.h instead.
|
||||
|
||||
Copyright (C) 2001 Niels Möller
|
||||
|
||||
This file is part of GNU Nettle.
|
||||
|
||||
GNU Nettle is free software: you can redistribute it and/or
|
||||
modify it under the terms of either:
|
||||
|
||||
* the GNU Lesser General Public License as published by the Free
|
||||
Software Foundation; either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or
|
||||
|
||||
* the GNU General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or both in parallel, as here.
|
||||
|
||||
GNU Nettle is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received copies of the GNU General Public License and
|
||||
the GNU Lesser General Public License along with this program. If
|
||||
not, see http://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
#ifndef NETTLE_SHA_H_INCLUDED
|
||||
#define NETTLE_SHA_H_INCLUDED
|
||||
|
||||
#include "sha1.h"
|
||||
#include "sha2.h"
|
||||
|
||||
#endif /* NETTLE_SHA_H_INCLUDED */
|
||||
@@ -1,88 +0,0 @@
|
||||
/* sha1.h
|
||||
|
||||
The sha1 hash function.
|
||||
|
||||
Copyright (C) 2001, 2012 Niels Möller
|
||||
|
||||
This file is part of GNU Nettle.
|
||||
|
||||
GNU Nettle is free software: you can redistribute it and/or
|
||||
modify it under the terms of either:
|
||||
|
||||
* the GNU Lesser General Public License as published by the Free
|
||||
Software Foundation; either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or
|
||||
|
||||
* the GNU General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or both in parallel, as here.
|
||||
|
||||
GNU Nettle is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received copies of the GNU General Public License and
|
||||
the GNU Lesser General Public License along with this program. If
|
||||
not, see http://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
#ifndef NETTLE_SHA1_H_INCLUDED
|
||||
#define NETTLE_SHA1_H_INCLUDED
|
||||
|
||||
#include "nettle-types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Name mangling */
|
||||
#define sha1_init nettle_sha1_init
|
||||
#define sha1_update nettle_sha1_update
|
||||
#define sha1_digest nettle_sha1_digest
|
||||
|
||||
/* SHA1 */
|
||||
|
||||
#define SHA1_DIGEST_SIZE 20
|
||||
#define SHA1_BLOCK_SIZE 64
|
||||
/* For backwards compatibility */
|
||||
#define SHA1_DATA_SIZE SHA1_BLOCK_SIZE
|
||||
|
||||
/* Digest is kept internally as 5 32-bit words. */
|
||||
#define _SHA1_DIGEST_LENGTH 5
|
||||
|
||||
struct sha1_ctx
|
||||
{
|
||||
uint32_t state[_SHA1_DIGEST_LENGTH]; /* State variables */
|
||||
uint64_t count; /* 64-bit block count */
|
||||
uint8_t block[SHA1_BLOCK_SIZE]; /* SHA1 data buffer */
|
||||
unsigned int index; /* index into buffer */
|
||||
};
|
||||
|
||||
void
|
||||
sha1_init(struct sha1_ctx *ctx);
|
||||
|
||||
void
|
||||
sha1_update(struct sha1_ctx *ctx,
|
||||
size_t length,
|
||||
const uint8_t *data);
|
||||
|
||||
void
|
||||
sha1_digest(struct sha1_ctx *ctx,
|
||||
size_t length,
|
||||
uint8_t *digest);
|
||||
|
||||
/* Internal compression function. STATE points to 5 uint32_t words,
|
||||
and DATA points to 64 bytes of input data, possibly unaligned. */
|
||||
void
|
||||
_nettle_sha1_compress(uint32_t *state, const uint8_t *data);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* NETTLE_SHA1_H_INCLUDED */
|
||||
@@ -1,206 +0,0 @@
|
||||
/* sha2.h
|
||||
|
||||
The sha2 family of hash functions.
|
||||
|
||||
Copyright (C) 2001, 2012 Niels Möller
|
||||
|
||||
This file is part of GNU Nettle.
|
||||
|
||||
GNU Nettle is free software: you can redistribute it and/or
|
||||
modify it under the terms of either:
|
||||
|
||||
* the GNU Lesser General Public License as published by the Free
|
||||
Software Foundation; either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or
|
||||
|
||||
* the GNU General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or both in parallel, as here.
|
||||
|
||||
GNU Nettle is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received copies of the GNU General Public License and
|
||||
the GNU Lesser General Public License along with this program. If
|
||||
not, see http://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
#ifndef NETTLE_SHA2_H_INCLUDED
|
||||
#define NETTLE_SHA2_H_INCLUDED
|
||||
|
||||
#include "nettle-types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Name mangling */
|
||||
#define sha224_init nettle_sha224_init
|
||||
#define sha224_digest nettle_sha224_digest
|
||||
#define sha256_init nettle_sha256_init
|
||||
#define sha256_update nettle_sha256_update
|
||||
#define sha256_digest nettle_sha256_digest
|
||||
#define sha384_init nettle_sha384_init
|
||||
#define sha384_digest nettle_sha384_digest
|
||||
#define sha512_init nettle_sha512_init
|
||||
#define sha512_update nettle_sha512_update
|
||||
#define sha512_digest nettle_sha512_digest
|
||||
#define sha512_224_init nettle_sha512_224_init
|
||||
#define sha512_224_digest nettle_sha512_224_digest
|
||||
#define sha512_256_init nettle_sha512_256_init
|
||||
#define sha512_256_digest nettle_sha512_256_digest
|
||||
|
||||
/* For backwards compatibility */
|
||||
#define SHA224_DATA_SIZE SHA256_BLOCK_SIZE
|
||||
#define SHA256_DATA_SIZE SHA256_BLOCK_SIZE
|
||||
#define SHA512_DATA_SIZE SHA512_BLOCK_SIZE
|
||||
#define SHA384_DATA_SIZE SHA512_BLOCK_SIZE
|
||||
|
||||
/* SHA256 */
|
||||
|
||||
#define SHA256_DIGEST_SIZE 32
|
||||
#define SHA256_BLOCK_SIZE 64
|
||||
|
||||
/* Digest is kept internally as 8 32-bit words. */
|
||||
#define _SHA256_DIGEST_LENGTH 8
|
||||
|
||||
struct sha256_ctx
|
||||
{
|
||||
uint32_t state[_SHA256_DIGEST_LENGTH]; /* State variables */
|
||||
uint64_t count; /* 64-bit block count */
|
||||
uint8_t block[SHA256_BLOCK_SIZE]; /* SHA256 data buffer */
|
||||
unsigned int index; /* index into buffer */
|
||||
};
|
||||
|
||||
void
|
||||
sha256_init(struct sha256_ctx *ctx);
|
||||
|
||||
void
|
||||
sha256_update(struct sha256_ctx *ctx,
|
||||
size_t length,
|
||||
const uint8_t *data);
|
||||
|
||||
void
|
||||
sha256_digest(struct sha256_ctx *ctx,
|
||||
size_t length,
|
||||
uint8_t *digest);
|
||||
|
||||
/* Internal compression function. STATE points to 8 uint32_t words,
|
||||
DATA points to 64 bytes of input data, possibly unaligned, and K
|
||||
points to the table of constants. */
|
||||
void
|
||||
_nettle_sha256_compress(uint32_t *state, const uint8_t *data, const uint32_t *k);
|
||||
|
||||
|
||||
/* SHA224, a truncated SHA256 with different initial state. */
|
||||
|
||||
#define SHA224_DIGEST_SIZE 28
|
||||
#define SHA224_BLOCK_SIZE SHA256_BLOCK_SIZE
|
||||
#define sha224_ctx sha256_ctx
|
||||
|
||||
void
|
||||
sha224_init(struct sha256_ctx *ctx);
|
||||
|
||||
#define sha224_update nettle_sha256_update
|
||||
|
||||
void
|
||||
sha224_digest(struct sha256_ctx *ctx,
|
||||
size_t length,
|
||||
uint8_t *digest);
|
||||
|
||||
|
||||
/* SHA512 */
|
||||
|
||||
#define SHA512_DIGEST_SIZE 64
|
||||
#define SHA512_BLOCK_SIZE 128
|
||||
|
||||
/* Digest is kept internally as 8 64-bit words. */
|
||||
#define _SHA512_DIGEST_LENGTH 8
|
||||
|
||||
struct sha512_ctx
|
||||
{
|
||||
uint64_t state[_SHA512_DIGEST_LENGTH]; /* State variables */
|
||||
uint64_t count_low, count_high; /* 128-bit block count */
|
||||
uint8_t block[SHA512_BLOCK_SIZE]; /* SHA512 data buffer */
|
||||
unsigned int index; /* index into buffer */
|
||||
};
|
||||
|
||||
void
|
||||
sha512_init(struct sha512_ctx *ctx);
|
||||
|
||||
void
|
||||
sha512_update(struct sha512_ctx *ctx,
|
||||
size_t length,
|
||||
const uint8_t *data);
|
||||
|
||||
void
|
||||
sha512_digest(struct sha512_ctx *ctx,
|
||||
size_t length,
|
||||
uint8_t *digest);
|
||||
|
||||
/* Internal compression function. STATE points to 8 uint64_t words,
|
||||
DATA points to 128 bytes of input data, possibly unaligned, and K
|
||||
points to the table of constants. */
|
||||
void
|
||||
_nettle_sha512_compress(uint64_t *state, const uint8_t *data, const uint64_t *k);
|
||||
|
||||
|
||||
/* SHA384, a truncated SHA512 with different initial state. */
|
||||
|
||||
#define SHA384_DIGEST_SIZE 48
|
||||
#define SHA384_BLOCK_SIZE SHA512_BLOCK_SIZE
|
||||
#define sha384_ctx sha512_ctx
|
||||
|
||||
void
|
||||
sha384_init(struct sha512_ctx *ctx);
|
||||
|
||||
#define sha384_update nettle_sha512_update
|
||||
|
||||
void
|
||||
sha384_digest(struct sha512_ctx *ctx,
|
||||
size_t length,
|
||||
uint8_t *digest);
|
||||
|
||||
|
||||
/* SHA512_224 and SHA512_256, two truncated versions of SHA512
|
||||
with different initial states. */
|
||||
|
||||
#define SHA512_224_DIGEST_SIZE 28
|
||||
#define SHA512_224_BLOCK_SIZE SHA512_BLOCK_SIZE
|
||||
#define sha512_224_ctx sha512_ctx
|
||||
|
||||
void
|
||||
sha512_224_init(struct sha512_224_ctx *ctx);
|
||||
|
||||
#define sha512_224_update nettle_sha512_update
|
||||
|
||||
void
|
||||
sha512_224_digest(struct sha512_224_ctx *ctx,
|
||||
size_t length,
|
||||
uint8_t *digest);
|
||||
|
||||
#define SHA512_256_DIGEST_SIZE 32
|
||||
#define SHA512_256_BLOCK_SIZE SHA512_BLOCK_SIZE
|
||||
#define sha512_256_ctx sha512_ctx
|
||||
|
||||
void
|
||||
sha512_256_init(struct sha512_256_ctx *ctx);
|
||||
|
||||
#define sha512_256_update nettle_sha512_update
|
||||
|
||||
void
|
||||
sha512_256_digest(struct sha512_256_ctx *ctx,
|
||||
size_t length,
|
||||
uint8_t *digest);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* NETTLE_SHA2_H_INCLUDED */
|
||||
@@ -1,193 +0,0 @@
|
||||
/* sha3.h
|
||||
|
||||
The sha3 hash function (aka Keccak).
|
||||
|
||||
Copyright (C) 2012 Niels Möller
|
||||
|
||||
This file is part of GNU Nettle.
|
||||
|
||||
GNU Nettle is free software: you can redistribute it and/or
|
||||
modify it under the terms of either:
|
||||
|
||||
* the GNU Lesser General Public License as published by the Free
|
||||
Software Foundation; either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or
|
||||
|
||||
* the GNU General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or both in parallel, as here.
|
||||
|
||||
GNU Nettle is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received copies of the GNU General Public License and
|
||||
the GNU Lesser General Public License along with this program. If
|
||||
not, see http://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
#ifndef NETTLE_SHA3_H_INCLUDED
|
||||
#define NETTLE_SHA3_H_INCLUDED
|
||||
|
||||
#include "nettle-types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Name mangling */
|
||||
#define sha3_permute nettle_sha3_permute
|
||||
#define _sha3_update _nettle_sha3_update
|
||||
#define _sha3_pad _nettle_sha3_pad
|
||||
#define sha3_224_init nettle_sha3_224_init
|
||||
#define sha3_224_update nettle_sha3_224_update
|
||||
#define sha3_224_digest nettle_sha3_224_digest
|
||||
#define sha3_256_init nettle_sha3_256_init
|
||||
#define sha3_256_update nettle_sha3_256_update
|
||||
#define sha3_256_digest nettle_sha3_256_digest
|
||||
#define sha3_384_init nettle_sha3_384_init
|
||||
#define sha3_384_update nettle_sha3_384_update
|
||||
#define sha3_384_digest nettle_sha3_384_digest
|
||||
#define sha3_512_init nettle_sha3_512_init
|
||||
#define sha3_512_update nettle_sha3_512_update
|
||||
#define sha3_512_digest nettle_sha3_512_digest
|
||||
|
||||
/* Indicates that SHA3 is the NIST FIPS 202 version. */
|
||||
#define NETTLE_SHA3_FIPS202 1
|
||||
|
||||
/* The sha3 state is a 5x5 matrix of 64-bit words. In the notation of
|
||||
Keccak description, S[x,y] is element x + 5*y, so if x is
|
||||
interpreted as the row index and y the column index, it is stored
|
||||
in column-major order. */
|
||||
#define SHA3_STATE_LENGTH 25
|
||||
|
||||
/* The "width" is 1600 bits or 200 octets */
|
||||
struct sha3_state
|
||||
{
|
||||
uint64_t a[SHA3_STATE_LENGTH];
|
||||
};
|
||||
|
||||
void
|
||||
sha3_permute (struct sha3_state *state);
|
||||
|
||||
unsigned
|
||||
_sha3_update (struct sha3_state *state,
|
||||
unsigned block_size, uint8_t *block,
|
||||
unsigned pos,
|
||||
size_t length, const uint8_t *data);
|
||||
void
|
||||
_sha3_pad (struct sha3_state *state,
|
||||
unsigned block_size, uint8_t *block, unsigned pos);
|
||||
|
||||
/* The "capacity" is set to 2*(digest size), 512 bits or 64 octets.
|
||||
The "rate" is the width - capacity, or width - 2 * (digest
|
||||
size). */
|
||||
|
||||
#define SHA3_224_DIGEST_SIZE 28
|
||||
#define SHA3_224_BLOCK_SIZE 144
|
||||
|
||||
#define SHA3_256_DIGEST_SIZE 32
|
||||
#define SHA3_256_BLOCK_SIZE 136
|
||||
|
||||
#define SHA3_384_DIGEST_SIZE 48
|
||||
#define SHA3_384_BLOCK_SIZE 104
|
||||
|
||||
#define SHA3_512_DIGEST_SIZE 64
|
||||
#define SHA3_512_BLOCK_SIZE 72
|
||||
|
||||
/* For backwards compatibility */
|
||||
#define SHA3_224_DATA_SIZE SHA3_224_BLOCK_SIZE
|
||||
#define SHA3_256_DATA_SIZE SHA3_256_BLOCK_SIZE
|
||||
#define SHA3_384_DATA_SIZE SHA3_384_BLOCK_SIZE
|
||||
#define SHA3_512_DATA_SIZE SHA3_512_BLOCK_SIZE
|
||||
|
||||
struct sha3_224_ctx
|
||||
{
|
||||
struct sha3_state state;
|
||||
unsigned index;
|
||||
uint8_t block[SHA3_224_BLOCK_SIZE];
|
||||
};
|
||||
|
||||
void
|
||||
sha3_224_init (struct sha3_224_ctx *ctx);
|
||||
|
||||
void
|
||||
sha3_224_update (struct sha3_224_ctx *ctx,
|
||||
size_t length,
|
||||
const uint8_t *data);
|
||||
|
||||
void
|
||||
sha3_224_digest(struct sha3_224_ctx *ctx,
|
||||
size_t length,
|
||||
uint8_t *digest);
|
||||
|
||||
struct sha3_256_ctx
|
||||
{
|
||||
struct sha3_state state;
|
||||
unsigned index;
|
||||
uint8_t block[SHA3_256_BLOCK_SIZE];
|
||||
};
|
||||
|
||||
void
|
||||
sha3_256_init (struct sha3_256_ctx *ctx);
|
||||
|
||||
void
|
||||
sha3_256_update (struct sha3_256_ctx *ctx,
|
||||
size_t length,
|
||||
const uint8_t *data);
|
||||
|
||||
void
|
||||
sha3_256_digest(struct sha3_256_ctx *ctx,
|
||||
size_t length,
|
||||
uint8_t *digest);
|
||||
|
||||
struct sha3_384_ctx
|
||||
{
|
||||
struct sha3_state state;
|
||||
unsigned index;
|
||||
uint8_t block[SHA3_384_BLOCK_SIZE];
|
||||
};
|
||||
|
||||
void
|
||||
sha3_384_init (struct sha3_384_ctx *ctx);
|
||||
|
||||
void
|
||||
sha3_384_update (struct sha3_384_ctx *ctx,
|
||||
size_t length,
|
||||
const uint8_t *data);
|
||||
|
||||
void
|
||||
sha3_384_digest(struct sha3_384_ctx *ctx,
|
||||
size_t length,
|
||||
uint8_t *digest);
|
||||
|
||||
struct sha3_512_ctx
|
||||
{
|
||||
struct sha3_state state;
|
||||
unsigned index;
|
||||
uint8_t block[SHA3_512_BLOCK_SIZE];
|
||||
};
|
||||
|
||||
void
|
||||
sha3_512_init (struct sha3_512_ctx *ctx);
|
||||
|
||||
void
|
||||
sha3_512_update (struct sha3_512_ctx *ctx,
|
||||
size_t length,
|
||||
const uint8_t *data);
|
||||
|
||||
void
|
||||
sha3_512_digest(struct sha3_512_ctx *ctx,
|
||||
size_t length,
|
||||
uint8_t *digest);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* NETTLE_SHA3_H_INCLUDED */
|
||||
@@ -1,98 +0,0 @@
|
||||
/* twofish.h
|
||||
|
||||
The twofish block cipher.
|
||||
|
||||
Copyright (C) 2001, 2014 Niels Möller
|
||||
|
||||
This file is part of GNU Nettle.
|
||||
|
||||
GNU Nettle is free software: you can redistribute it and/or
|
||||
modify it under the terms of either:
|
||||
|
||||
* the GNU Lesser General Public License as published by the Free
|
||||
Software Foundation; either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or
|
||||
|
||||
* the GNU General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or both in parallel, as here.
|
||||
|
||||
GNU Nettle is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received copies of the GNU General Public License and
|
||||
the GNU Lesser General Public License along with this program. If
|
||||
not, see http://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Twofish is a 128-bit block cipher that accepts a variable-length
|
||||
* key up to 256 bits, designed by Bruce Schneier and others. See
|
||||
* http://www.counterpane.com/twofish.html for details.
|
||||
*/
|
||||
|
||||
#ifndef NETTLE_TWOFISH_H_INCLUDED
|
||||
#define NETTLE_TWOFISH_H_INCLUDED
|
||||
|
||||
#include "nettle-types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Name mangling */
|
||||
#define twofish_set_key nettle_twofish_set_key
|
||||
#define twofish128_set_key nettle_twofish128_set_key
|
||||
#define twofish192_set_key nettle_twofish192_set_key
|
||||
#define twofish256_set_key nettle_twofish256_set_key
|
||||
#define twofish_encrypt nettle_twofish_encrypt
|
||||
#define twofish_decrypt nettle_twofish_decrypt
|
||||
|
||||
#define TWOFISH_BLOCK_SIZE 16
|
||||
|
||||
/* Variable key size between 128 and 256 bits. But the only valid
|
||||
* values are 16 (128 bits), 24 (192 bits) and 32 (256 bits). */
|
||||
#define TWOFISH_MIN_KEY_SIZE 16
|
||||
#define TWOFISH_MAX_KEY_SIZE 32
|
||||
|
||||
#define TWOFISH_KEY_SIZE 32
|
||||
#define TWOFISH128_KEY_SIZE 16
|
||||
#define TWOFISH192_KEY_SIZE 24
|
||||
#define TWOFISH256_KEY_SIZE 32
|
||||
|
||||
struct twofish_ctx
|
||||
{
|
||||
uint32_t keys[40];
|
||||
uint32_t s_box[4][256];
|
||||
};
|
||||
|
||||
void
|
||||
twofish_set_key(struct twofish_ctx *ctx,
|
||||
size_t length, const uint8_t *key);
|
||||
void
|
||||
twofish128_set_key(struct twofish_ctx *context, const uint8_t *key);
|
||||
void
|
||||
twofish192_set_key(struct twofish_ctx *context, const uint8_t *key);
|
||||
void
|
||||
twofish256_set_key(struct twofish_ctx *context, const uint8_t *key);
|
||||
|
||||
void
|
||||
twofish_encrypt(const struct twofish_ctx *ctx,
|
||||
size_t length, uint8_t *dst,
|
||||
const uint8_t *src);
|
||||
void
|
||||
twofish_decrypt(const struct twofish_ctx *ctx,
|
||||
size_t length, uint8_t *dst,
|
||||
const uint8_t *src);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* NETTLE_TWOFISH_H_INCLUDED */
|
||||
@@ -1,253 +0,0 @@
|
||||
/* umac.h
|
||||
|
||||
UMAC message authentication code (RFC-4418).
|
||||
|
||||
Copyright (C) 2013 Niels Möller
|
||||
|
||||
This file is part of GNU Nettle.
|
||||
|
||||
GNU Nettle is free software: you can redistribute it and/or
|
||||
modify it under the terms of either:
|
||||
|
||||
* the GNU Lesser General Public License as published by the Free
|
||||
Software Foundation; either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or
|
||||
|
||||
* the GNU General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
or both in parallel, as here.
|
||||
|
||||
GNU Nettle is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received copies of the GNU General Public License and
|
||||
the GNU Lesser General Public License along with this program. If
|
||||
not, see http://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
#ifndef NETTLE_UMAC_H_INCLUDED
|
||||
#define NETTLE_UMAC_H_INCLUDED
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Namespace mangling */
|
||||
#define umac32_set_key nettle_umac32_set_key
|
||||
#define umac64_set_key nettle_umac64_set_key
|
||||
#define umac96_set_key nettle_umac96_set_key
|
||||
#define umac128_set_key nettle_umac128_set_key
|
||||
#define umac32_set_nonce nettle_umac32_set_nonce
|
||||
#define umac64_set_nonce nettle_umac64_set_nonce
|
||||
#define umac96_set_nonce nettle_umac96_set_nonce
|
||||
#define umac128_set_nonce nettle_umac128_set_nonce
|
||||
#define umac32_update nettle_umac32_update
|
||||
#define umac64_update nettle_umac64_update
|
||||
#define umac96_update nettle_umac96_update
|
||||
#define umac128_update nettle_umac128_update
|
||||
#define umac32_digest nettle_umac32_digest
|
||||
#define umac64_digest nettle_umac64_digest
|
||||
#define umac96_digest nettle_umac96_digest
|
||||
#define umac128_digest nettle_umac128_digest
|
||||
#define _umac_set_key _nettle_umac_set_key
|
||||
#define _umac_nh _nettle_umac_nh
|
||||
#define _umac_nh_n _nettle_umac_nh_n
|
||||
#define _umac_poly64 _nettle_umac_poly64
|
||||
#define _umac_poly128 _nettle_umac_poly128
|
||||
#define _umac_l2_init _nettle_umac_l2_init
|
||||
#define _umac_l2 _nettle_umac_l2
|
||||
#define _umac_l2_final _nettle_umac_l2_final
|
||||
#define _umac_l3_init _nettle_umac_l3_init
|
||||
#define _umac_l3 _nettle_umac_l3
|
||||
|
||||
#include "nettle-types.h"
|
||||
#include "aes.h"
|
||||
|
||||
#define UMAC_KEY_SIZE AES128_KEY_SIZE
|
||||
#define UMAC32_DIGEST_SIZE 4
|
||||
#define UMAC64_DIGEST_SIZE 8
|
||||
#define UMAC96_DIGEST_SIZE 12
|
||||
#define UMAC128_DIGEST_SIZE 16
|
||||
#define UMAC_BLOCK_SIZE 1024
|
||||
#define UMAC_MIN_NONCE_SIZE 1
|
||||
#define UMAC_MAX_NONCE_SIZE AES_BLOCK_SIZE
|
||||
/* For backwards compatibility */
|
||||
#define UMAC_DATA_SIZE UMAC_BLOCK_SIZE
|
||||
|
||||
/* Subkeys and state for UMAC with tag size 32*n bits. */
|
||||
#define _UMAC_STATE(n) \
|
||||
uint32_t l1_key[UMAC_BLOCK_SIZE/4 + 4*((n)-1)]; \
|
||||
/* Keys in 32-bit pieces, high first */ \
|
||||
uint32_t l2_key[6*(n)]; \
|
||||
uint64_t l3_key1[8*(n)]; \
|
||||
uint32_t l3_key2[(n)]; \
|
||||
/* AES cipher for encrypting the nonce */ \
|
||||
struct aes128_ctx pdf_key; \
|
||||
/* The l2_state consists of 2*n uint64_t, for poly64 \
|
||||
and poly128 hashing, followed by n additional \
|
||||
uint64_t used as an input buffer. */ \
|
||||
uint64_t l2_state[3*(n)]; \
|
||||
/* Input to the pdf_key, zero-padded and low bits \
|
||||
cleared if appropriate. */ \
|
||||
uint8_t nonce[AES_BLOCK_SIZE]; \
|
||||
unsigned short nonce_length /* For incrementing */
|
||||
|
||||
/* Buffering */
|
||||
#define _UMAC_BUFFER \
|
||||
unsigned index; \
|
||||
/* Complete blocks processed */ \
|
||||
uint64_t count; \
|
||||
uint8_t block[UMAC_BLOCK_SIZE]
|
||||
|
||||
#define _UMAC_NONCE_CACHED 0x80
|
||||
|
||||
struct umac32_ctx
|
||||
{
|
||||
_UMAC_STATE(1);
|
||||
/* Low bits and cache flag. */
|
||||
unsigned short nonce_low;
|
||||
/* Previous padding block */
|
||||
uint32_t pad_cache[AES_BLOCK_SIZE / 4];
|
||||
_UMAC_BUFFER;
|
||||
};
|
||||
|
||||
struct umac64_ctx
|
||||
{
|
||||
_UMAC_STATE(2);
|
||||
/* Low bit and cache flag. */
|
||||
unsigned short nonce_low;
|
||||
/* Previous padding block */
|
||||
uint32_t pad_cache[AES_BLOCK_SIZE/4];
|
||||
_UMAC_BUFFER;
|
||||
};
|
||||
|
||||
struct umac96_ctx
|
||||
{
|
||||
_UMAC_STATE(3);
|
||||
_UMAC_BUFFER;
|
||||
};
|
||||
|
||||
struct umac128_ctx
|
||||
{
|
||||
_UMAC_STATE(4);
|
||||
_UMAC_BUFFER;
|
||||
};
|
||||
|
||||
/* The _set_key function initialize the nonce to zero. */
|
||||
void
|
||||
umac32_set_key (struct umac32_ctx *ctx, const uint8_t *key);
|
||||
void
|
||||
umac64_set_key (struct umac64_ctx *ctx, const uint8_t *key);
|
||||
void
|
||||
umac96_set_key (struct umac96_ctx *ctx, const uint8_t *key);
|
||||
void
|
||||
umac128_set_key (struct umac128_ctx *ctx, const uint8_t *key);
|
||||
|
||||
/* Optional, if not used, messages get incrementing nonces starting from zero. */
|
||||
void
|
||||
umac32_set_nonce (struct umac32_ctx *ctx,
|
||||
size_t nonce_length, const uint8_t *nonce);
|
||||
void
|
||||
umac64_set_nonce (struct umac64_ctx *ctx,
|
||||
size_t nonce_length, const uint8_t *nonce);
|
||||
void
|
||||
umac96_set_nonce (struct umac96_ctx *ctx,
|
||||
size_t nonce_length, const uint8_t *nonce);
|
||||
void
|
||||
umac128_set_nonce (struct umac128_ctx *ctx,
|
||||
size_t nonce_length, const uint8_t *nonce);
|
||||
|
||||
void
|
||||
umac32_update (struct umac32_ctx *ctx,
|
||||
size_t length, const uint8_t *data);
|
||||
void
|
||||
umac64_update (struct umac64_ctx *ctx,
|
||||
size_t length, const uint8_t *data);
|
||||
void
|
||||
umac96_update (struct umac96_ctx *ctx,
|
||||
size_t length, const uint8_t *data);
|
||||
void
|
||||
umac128_update (struct umac128_ctx *ctx,
|
||||
size_t length, const uint8_t *data);
|
||||
|
||||
/* The _digest functions increment the nonce */
|
||||
void
|
||||
umac32_digest (struct umac32_ctx *ctx,
|
||||
size_t length, uint8_t *digest);
|
||||
void
|
||||
umac64_digest (struct umac64_ctx *ctx,
|
||||
size_t length, uint8_t *digest);
|
||||
void
|
||||
umac96_digest (struct umac96_ctx *ctx,
|
||||
size_t length, uint8_t *digest);
|
||||
void
|
||||
umac128_digest (struct umac128_ctx *ctx,
|
||||
size_t length, uint8_t *digest);
|
||||
|
||||
|
||||
/* Internal functions */
|
||||
#define UMAC_POLY64_BLOCKS 16384
|
||||
|
||||
#define UMAC_P64_OFFSET 59
|
||||
#define UMAC_P64 (- (uint64_t) UMAC_P64_OFFSET)
|
||||
|
||||
#define UMAC_P128_OFFSET 159
|
||||
#define UMAC_P128_HI (~(uint64_t) 0)
|
||||
#define UMAC_P128_LO (-(uint64_t) UMAC_P128_OFFSET)
|
||||
|
||||
void
|
||||
_umac_set_key (uint32_t *l1_key, uint32_t *l2_key,
|
||||
uint64_t *l3_key1, uint32_t *l3_key2,
|
||||
struct aes128_ctx *pad, const uint8_t *key, unsigned n);
|
||||
|
||||
uint64_t
|
||||
_umac_nh (const uint32_t *key, unsigned length, const uint8_t *msg);
|
||||
|
||||
/* Equivalent to
|
||||
|
||||
for (i = 0; i < n; i++)
|
||||
out[i] = _umac_nh (key + 4*i, length, msg);
|
||||
|
||||
but processing input only once.
|
||||
*/
|
||||
void
|
||||
_umac_nh_n (uint64_t *out, unsigned n, const uint32_t *key,
|
||||
unsigned length, const uint8_t *msg);
|
||||
|
||||
/* Returns y*k + m (mod p), including "marker" processing. Return
|
||||
value is *not* in canonical representation, and must be normalized
|
||||
before the output is used. */
|
||||
uint64_t
|
||||
_umac_poly64 (uint32_t kh, uint32_t kl, uint64_t y, uint64_t m);
|
||||
|
||||
void
|
||||
_umac_poly128 (const uint32_t *k, uint64_t *y, uint64_t mh, uint64_t ml);
|
||||
|
||||
void
|
||||
_umac_l2_init (unsigned size, uint32_t *k);
|
||||
|
||||
void
|
||||
_umac_l2(const uint32_t *key, uint64_t *state, unsigned n,
|
||||
uint64_t count, const uint64_t *m);
|
||||
|
||||
void
|
||||
_umac_l2_final(const uint32_t *key, uint64_t *state, unsigned n,
|
||||
uint64_t count);
|
||||
|
||||
void
|
||||
_umac_l3_init (unsigned size, uint64_t *k);
|
||||
|
||||
uint32_t
|
||||
_umac_l3 (const uint64_t *key, const uint64_t *m);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* NETTLE_UMAC_H_INCLUDED */
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user