Repository: conan-io/conan-center-index

Issue:
[request] libsrtp/2.3.0
### Package Details
  * Package Name/Version: **libsrtp/2.3.0**
  * Website: **https://github.com/cisco/libsrtp**
  * Source code: **https://github.com/cisco/libsrtp**


### Description Of The Library / Tool
This package provides an implementation of the Secure Real-time Transport Protocol (SRTP), the Universal Security Transform (UST), and a supporting cryptographic kernel. The SRTP API is documented in include/srtp.h, and the library is in libsrtp2.a (after compilation).


Discussion:
I will give this a try

Is this license a problem? 
```
 * Copyright (c) 2001-2017 Cisco Systems, Inc.
 * All rights reserved.
```
https://github.com/cisco/libsrtp/blob/master/LICENSE#L3-L4

Resolving patch:
diff --git a/recipes/libsrtp/all/conanfile.py b/recipes/libsrtp/all/conanfile.py
new file mode 100644
--- /dev/null
+++ b/recipes/libsrtp/all/conanfile.py
@@ -0,0 +1,90 @@
+import os
+from conans import ConanFile, CMake, tools
+
+
+class ConanRecipe(ConanFile):
+    name = "libsrtp"
+    description = (
+        "This package provides an implementation of the Secure Real-time Transport"
+        "Protocol (SRTP), the Universal Security Transform (UST), and a supporting"
+        "cryptographic kernel."
+    )
+    topics = ("conan", "libsrtp", "srtp")
+    homepage = "https://github.com/cisco/libsrtp"
+    url = "https://github.com/conan-io/conan-center-index"
+    license = "BSD-3-Clause"
+    exports_sources = ["CMakeLists.txt"]
+    generators = "cmake"
+
+    settings = "os", "arch", "compiler", "build_type"
+    options = {
+        "shared": [True, False],
+        "fPIC": [True, False],
+        "with_openssl": [True, False],
+    }
+    default_options = {
+        "shared": False,
+        "fPIC": True,
+        "with_openssl": False,
+    }
+
+    _cmake = None
+
+    @property
+    def _source_subfolder(self):
+        return "source_subfolder"
+
+    def config_options(self):
+        if self.settings.os == "Windows":
+            del self.options.fPIC
+
+    def configure(self):
+        if self.options.shared:
+            del self.options.fPIC
+        del self.settings.compiler.cppstd
+        del self.settings.compiler.libcxx
+
+    def requirements(self):
+        if self.options.with_openssl:
+            self.requires("openssl/1.1.1i")
+
+    def source(self):
+        tools.get(**self.conan_data["sources"][self.version])
+        extracted_dir = self.name + "-" + self.version
+        os.rename(extracted_dir, self._source_subfolder)
+
+    def _configure_cmake(self):
+        if self._cmake:
+            return self._cmake
+        self._cmake = CMake(self)
+        self._cmake.definitions["ENABLE_OPENSSL"] = self.options.with_openssl
+        self._cmake.definitions["TEST_APPS"] = False
+        self._cmake.configure()
+        return self._cmake
+
+    def build(self):
+        tools.replace_in_file(
+            os.path.join(self._source_subfolder, "CMakeLists.txt"),
+            "install(TARGETS srtp2 DESTINATION lib)",
+            (
+                "include(GNUInstallDirs)\n"
+                "install(TARGETS srtp2\n"
+                "RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}\n"
+                "LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}\n"
+                "ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})"
+            ),
+        )
+        cmake = self._configure_cmake()
+        cmake.build()
+
+    def package(self):
+        self.copy("LICENSE", dst="licenses", src=self._source_subfolder)
+        cmake = self._configure_cmake()
+        cmake.install()
+
+    def package_info(self):
+        libsrtp_major = tools.Version(self.version).major
+        self.cpp_info.names["pkg_config"] = "libsrtp{}".format(libsrtp_major if int(libsrtp_major) > 1 else "")
+        self.cpp_info.libs = tools.collect_libs(self)
+        if self.settings.os == "Windows":
+            self.cpp_info.system_libs = ["ws2_32"]


Test patch:
diff --git a/recipes/libsrtp/all/test_package/CMakeLists.txt b/recipes/libsrtp/all/test_package/CMakeLists.txt
new file mode 100644
--- /dev/null
+++ b/recipes/libsrtp/all/test_package/CMakeLists.txt
@@ -0,0 +1,11 @@
+cmake_minimum_required(VERSION 3.1)
+project(test_package C)
+
+include("${CMAKE_BINARY_DIR}/conanbuildinfo.cmake")
+conan_basic_setup(TARGETS)
+
+find_package(libsrtp REQUIRED CONFIG)
+
+add_executable(test_package test_package.c)
+
+target_link_libraries(test_package PRIVATE libsrtp::libsrtp)
diff --git a/recipes/libsrtp/all/test_package/conanfile.py b/recipes/libsrtp/all/test_package/conanfile.py
new file mode 100644
--- /dev/null
+++ b/recipes/libsrtp/all/test_package/conanfile.py
@@ -0,0 +1,17 @@
+import os
+
+from conans import ConanFile, CMake, tools
+
+class TestPackageConan(ConanFile):
+    settings = "os", "compiler", "build_type", "arch"
+    generators = "cmake", "cmake_find_package_multi"
+
+    def build(self):
+        cmake = CMake(self)
+        cmake.configure()
+        cmake.build()
+
+    def test(self):
+        if not tools.cross_building(self.settings):
+            bin_path = os.path.join("bin", "test_package")
+            self.run(bin_path, run_environment=True)
diff --git a/recipes/libsrtp/all/test_package/test_package.c b/recipes/libsrtp/all/test_package/test_package.c
new file mode 100644
--- /dev/null
+++ b/recipes/libsrtp/all/test_package/test_package.c
@@ -0,0 +1,33 @@
+// from: https://github.com/cisco/libsrtp#example-code
+
+#include <srtp2/srtp.h>
+
+#include <string.h>
+
+int main(void)
+{
+	srtp_t session;
+	srtp_policy_t policy;
+
+	// Set key to predetermined value
+	uint8_t key[30] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+					   0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
+					   0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
+					   0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D};
+
+	// initialize libSRTP
+	srtp_init();
+
+	// default policy values
+	memset(&policy, 0x0, sizeof(srtp_policy_t));
+
+	// set policy to describe a policy for an SRTP stream
+	srtp_crypto_policy_set_rtp_default(&policy.rtp);
+	srtp_crypto_policy_set_rtcp_default(&policy.rtcp);
+	policy.key = key;
+
+	// allocate and initialize the SRTP session
+	srtp_create(&session, &policy);
+
+	return 0;
+}