[前][次][番号順一覧][スレッド一覧]

ruby-changes:52387

From: nobu <ko1@a...>
Date: Fri, 31 Aug 2018 18:56:29 +0900 (JST)
Subject: [ruby-changes:52387] nobu:r64596 (trunk): random.c: SecRandomCopyBytes

nobu	2018-08-31 18:56:24 +0900 (Fri, 31 Aug 2018)

  New Revision: 64596

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=64596

  Log:
    random.c: SecRandomCopyBytes
    
    * random.c (fill_random_bytes_syscall): use SecRandomCopyBytes in
      Security framework on macOS 10.7 or later.

  Modified files:
    trunk/configure.ac
    trunk/random.c
Index: random.c
===================================================================
--- random.c	(revision 64595)
+++ random.c	(revision 64596)
@@ -470,6 +470,26 @@ fill_random_bytes_urandom(void *seed, si https://github.com/ruby/ruby/blob/trunk/random.c#L470
 #endif
 
 #if 0
+#elif defined __APPLE__ && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_7
+#include <Security/Security.h>
+
+static int
+fill_random_bytes_syscall(void *seed, size_t size, int unused)
+{
+    int status = SecRandomCopyBytes(kSecRandomDefault, size, seed);
+
+    if (status != errSecSuccess) {
+# if 0
+        CFStringRef s = SecCopyErrorMessageString(status, NULL);
+        const char *m = s ? CFStringGetCStringPtr(s, kCFStringEncodingUTF8) : NULL;
+        fprintf(stderr, "SecRandomCopyBytes failed: %d: %s\n", status,
+                m ? m : "unknown");
+        if (s) CFRelease(s);
+# endif
+        return -1;
+    }
+    return 0;
+}
 #elif defined(HAVE_ARC4RANDOM_BUF)
 static int
 fill_random_bytes_syscall(void *buf, size_t size, int unused)
Index: configure.ac
===================================================================
--- configure.ac	(revision 64595)
+++ configure.ac	(revision 64596)
@@ -3309,6 +3309,14 @@ AS_CASE(["$target_os"], https://github.com/ruby/ruby/blob/trunk/configure.ac#L3309
 	],
     [darwin*], [
 	RUBY_APPEND_OPTION(CFLAGS, -pipe)
+	AC_COMPILE_IFELSE([
+	    AC_LANG_BOOL_COMPILE_TRY([@%:@include <AvailabilityMacros.h>],
+		[MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_7])],
+	    [dnl
+		RUBY_APPEND_OPTION(XLDFLAGS, [-framework Security])
+		RUBY_APPEND_OPTION(LIBRUBYARG_STATIC, [-framework Security])
+	    ]dnl
+	)
 	RUBY_APPEND_OPTION(XLDFLAGS, [-framework Foundation])
 	RUBY_APPEND_OPTION(LIBRUBYARG_STATIC, [-framework Foundation])
 	],

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]