Skip to content

Commit b29e81c

Browse files
author
James Morris
committed
Merge pull request #25 from residuum/libgcrypt
Removed openssl and use libgcrypt.
2 parents 6263bcf + ae313ae commit b29e81c

File tree

5 files changed

+96
-13
lines changed

5 files changed

+96
-13
lines changed

CMakeLists.txt

+8-6
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,16 @@ set(ARCHIVE_NAME petri-foo-0.${Petri-Foo_VERSION_MAJOR}.${Petri-Foo_VERSION_MINO
2020
# two #defines to aid stripping path info from debug message output:
2121
# see config.h.in
2222
set(SRC_DIR $PROJECT_SOURCE_DIR)
23-
string( LENGTH "${PROJECT_SOURCE_DIR}" SRC_DIR_STRLEN)
2423

24+
# where to look first for cmake modules, before ${CMAKE_ROOT}/Modules/ is checked
25+
set(CMAKE_MODULE_PATH
26+
${CMAKE_SOURCE_DIR}/cmake/Modules
27+
)
28+
29+
string( LENGTH "${PROJECT_SOURCE_DIR}" SRC_DIR_STRLEN)
2530
include (CheckCSourceCompiles)
2631
INCLUDE (CheckIncludeFiles)
2732

28-
2933
mark_as_advanced(EXECUTABLE_OUTPUT_PATH)
3034
mark_as_advanced(LIBRARY_OUTPUT_PATH)
3135
mark_as_advanced(CMAKE_BUILD_TYPE)
@@ -85,7 +89,6 @@ endif (JACK_FOUND)
8589

8690
include (FindALSA)
8791

88-
8992
# SNDFILE
9093
pkg_check_modules (SNDFILE REQUIRED sndfile)
9194
if (SNDFILE_FOUND)
@@ -139,9 +142,6 @@ else (LIBLO_FOUND)
139142
endif (LIBLO_FOUND)
140143

141144

142-
include(FindOpenSSL)
143-
144-
145145
# Check for CAIRO_OPERATOR_HSL_LUMINOSITY
146146
check_c_source_compiles (
147147
"#include <cairo/cairo.h>
@@ -154,6 +154,8 @@ check_c_source_compiles (
154154

155155
CHECK_INCLUDE_FILES (malloc.h HAVE_MALLOC_H)
156156
CHECK_INCLUDE_FILES (jack/session.h HAVE_JACK_SESSION_H)
157+
158+
find_package(GCrypt 1.5.0 REQUIRED)
157159
CONFIGURE_FILE( ${CMAKE_CURRENT_SOURCE_DIR}/config.h.in
158160
${CMAKE_CURRENT_SOURCE_DIR}/config.h )
159161

cmake/Modules/FindGCrypt.cmake

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# - Try to find GCrypt
2+
# Once done this will define
3+
#
4+
# GCRYPT_FOUND - system has GCrypt
5+
# GCRYPT_INCLUDE_DIRS - the GCrypt include directory
6+
# GCRYPT_LIBRARIES - Link these to use GCrypt
7+
# GCRYPT_DEFINITIONS - Compiler switches required for using GCrypt
8+
#
9+
#=============================================================================
10+
# Copyright (c) 2009-2012 Andreas Schneider <[email protected]>
11+
#
12+
# Distributed under the OSI-approved BSD License (the "License");
13+
# see accompanying file Copyright.txt for details.
14+
#
15+
# This software is distributed WITHOUT ANY WARRANTY; without even the
16+
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17+
# See the License for more information.
18+
#=============================================================================
19+
#
20+
21+
set(_GCRYPT_ROOT_HINTS
22+
$ENV{GCRYTPT_ROOT_DIR}
23+
${GCRYPT_ROOT_DIR})
24+
25+
set(_GCRYPT_ROOT_PATHS
26+
"$ENV{PROGRAMFILES}/libgcrypt")
27+
28+
set(_GCRYPT_ROOT_HINTS_AND_PATHS
29+
HINTS ${_GCRYPT_ROOT_HINTS}
30+
PATHS ${_GCRYPT_ROOT_PATHS})
31+
32+
33+
find_path(GCRYPT_INCLUDE_DIR
34+
NAMES
35+
gcrypt.h
36+
HINTS
37+
${_GCRYPT_ROOT_HINTS_AND_PATHS}
38+
)
39+
40+
find_library(GCRYPT_LIBRARY
41+
NAMES
42+
gcrypt
43+
gcrypt11
44+
libgcrypt-11
45+
HINTS
46+
${_GCRYPT_ROOT_HINTS_AND_PATHS}
47+
)
48+
set(GCRYPT_LIBRARIES ${GCRYPT_LIBRARY})
49+
50+
if (GCRYPT_INCLUDE_DIR)
51+
file(STRINGS "${GCRYPT_INCLUDE_DIR}/gcrypt.h" _gcrypt_version_str REGEX "^#define GCRYPT_VERSION \"[0-9]+.[0-9]+.[0-9]+\"")
52+
53+
string(REGEX REPLACE "^.*GCRYPT_VERSION.*([0-9]+.[0-9]+.[0-9]+).*" "\\1" GCRYPT_VERSION "${_gcrypt_version_str}")
54+
endif (GCRYPT_INCLUDE_DIR)
55+
56+
include(FindPackageHandleStandardArgs)
57+
if (GCRYPT_VERSION)
58+
find_package_handle_standard_args(GCrypt
59+
REQUIRED_VARS
60+
GCRYPT_INCLUDE_DIR
61+
GCRYPT_LIBRARIES
62+
VERSION_VAR
63+
GCRYPT_VERSION
64+
FAIL_MESSAGE
65+
"Could NOT find GCrypt, try to set the path to GCrypt root folder in the system variable GCRYPT_ROOT_DIR"
66+
)
67+
else (GCRYPT_VERSION)
68+
find_package_handle_standard_args(GCrypt
69+
"Could NOT find GCrypt, try to set the path to GCrypt root folder in the system variable GCRYPT_ROOT_DIR"
70+
GCRYPT_INCLUDE_DIR
71+
GCRYPT_LIBRARIES)
72+
endif (GCRYPT_VERSION)
73+
74+
# show the GCRYPT_INCLUDE_DIRS and GCRYPT_LIBRARIES variables only in the advanced view
75+
mark_as_advanced(GCRYPT_INCLUDE_DIR GCRYPT_LIBRARIES)
76+

libpetrifui/CMakeLists.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ file (GLOB LIBPETRIFUI_SOURCES *.c)
44
include_directories (
55
${Petri-Foo_SOURCE_DIR}/libpetrifoo
66
${LIBXML2_INCLUDE_DIR}
7-
${OPENSSL_INCLUDE_DIR}
7+
${GCRYPTG_INCLUDE_DIR}
88
)
99

1010

@@ -17,5 +17,5 @@ add_library( petrifui ${LIBPETRIFUI_SOURCES})
1717
target_link_Libraries( petrifui
1818
petrifoo
1919
${LIBXML2_LIBRARIES}
20-
${OPENSSL_LIBRARIES}
20+
${GCRYPT_LIBRARIES}
2121
)

libpetrifui/dish_file.c

-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
#include "dish_file.h"
2222

2323
#include <libxml/parser.h>
24-
#include <openssl/sha.h>
2524
#include <stdbool.h>
2625
#include <stdio.h>
2726
#include <stdlib.h>

libpetrifui/file_ops.c

+10-4
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
#include <assert.h>
2424
#include <limits.h>
25-
#include <openssl/sha.h>
25+
#include <gcrypt.h>
2626
#include <stdio.h>
2727
#include <stdlib.h>
2828
#include <string.h>
@@ -192,6 +192,7 @@ char* file_ops_dir_to_hash(const char* path)
192192
{
193193
size_t len;
194194
unsigned char* h;
195+
size_t h_len;
195196
char* buf;
196197
char* b;
197198
int n;
@@ -206,12 +207,17 @@ char* file_ops_dir_to_hash(const char* path)
206207
if (path[len - 1] == '/')
207208
--len;
208209

209-
h = SHA1((unsigned char*)path, len, NULL);
210-
buf = malloc(sizeof(*b) * SHA_DIGEST_LENGTH * 2 + 1);
210+
h_len = gcry_md_get_algo_dlen(GCRY_MD_SHA1);
211+
h = malloc(sizeof(char) * h_len);
212+
gcry_md_hash_buffer(GCRY_MD_SHA1, h, path, len);
211213

212-
for (n = 0, b = buf; n < SHA_DIGEST_LENGTH; ++n, b += 2, ++h)
214+
buf = malloc(sizeof(*b) * h_len * 2 + 1);
215+
216+
for (n = 0, b = buf; n < h_len; ++n, b += 2, ++h)
213217
snprintf(b, 3, "%02x", (unsigned)*h);
214218

219+
free(h);
220+
215221
return buf;
216222
}
217223

0 commit comments

Comments
 (0)