[svn] GnuPG - r4410 - in trunk: . agent jnlib
svn author wk
cvs at cvs.gnupg.org
Thu Jan 25 11:26:56 CET 2007
Author: wk
Date: 2007-01-25 11:26:55 +0100 (Thu, 25 Jan 2007)
New Revision: 4410
Modified:
trunk/TODO
trunk/agent/ChangeLog
trunk/agent/genkey.c
trunk/jnlib/ChangeLog
trunk/jnlib/stringhelp.c
trunk/jnlib/stringhelp.h
Log:
jnlib/
* stringhelp.c (utf8_charcount): New.
agent/
* genkey.c (check_passphrase_constraints): Use UTF-8 aware strlen.
Modified: trunk/TODO
===================================================================
--- trunk/TODO 2007-01-25 09:15:10 UTC (rev 4409)
+++ trunk/TODO 2007-01-25 10:26:55 UTC (rev 4410)
@@ -120,6 +120,4 @@
There is at least one couple of duplicate files: inttype[_-]h.m4.
* UTF-8
-** we need a function to count characters.
- Something like utf8_strlen. This is needed to correclty count the
- lengtgh of a passphrase.
+ UTF-8 specific TODO.
Modified: trunk/agent/ChangeLog
===================================================================
--- trunk/agent/ChangeLog 2007-01-25 09:15:10 UTC (rev 4409)
+++ trunk/agent/ChangeLog 2007-01-25 10:26:55 UTC (rev 4410)
@@ -1,9 +1,10 @@
2007-01-25 Werner Koch <wk at g10code.com>
- * genkey.c (check_passphrase_constraints): Get ngettext call right.
+ * genkey.c (check_passphrase_constraints): Get ngettext call right
+ and use UTF-8 aware strlen.
* protect-tool.c (get_passphrase): New arg OPT_CHECK.
- (get_new_passphrase): Enable OTP_CHECK on the first call.
+ (get_new_passphrase): Enable OPT_CHECK on the first call.
* command.c (cmd_get_passphrase): Implement option --check.
2007-01-24 Werner Koch <wk at g10code.com>
Modified: trunk/agent/genkey.c
===================================================================
--- trunk/agent/genkey.c 2007-01-25 09:15:10 UTC (rev 4409)
+++ trunk/agent/genkey.c 2007-01-25 10:26:55 UTC (rev 4410)
@@ -84,7 +84,7 @@
if (!pw)
pw = "";
- if (strlen (pw) < minlen ) /* FIXME: should be an utf-8 length. */
+ if (utf8_charcount (pw) < minlen )
{
char *desc = xtryasprintf
( ngettext ("Warning: You have entered a passphrase that%%0A"
Modified: trunk/jnlib/ChangeLog
===================================================================
--- trunk/jnlib/ChangeLog 2007-01-25 09:15:10 UTC (rev 4409)
+++ trunk/jnlib/ChangeLog 2007-01-25 10:26:55 UTC (rev 4410)
@@ -1,3 +1,7 @@
+2007-01-25 Werner Koch <wk at g10code.com>
+
+ * stringhelp.c (utf8_charcount): New.
+
2006-11-29 Werner Koch <wk at g10code.com>
* utf8conv.c (set_native_charset) [HAVE_W32_SYSTEM]: Fixed typo in
Modified: trunk/jnlib/stringhelp.c
===================================================================
--- trunk/jnlib/stringhelp.c 2007-01-25 09:15:10 UTC (rev 4409)
+++ trunk/jnlib/stringhelp.c 2007-01-25 10:26:55 UTC (rev 4410)
@@ -547,6 +547,23 @@
}
+/* Given a string containing an UTF-8 encoded text, return the number
+ of characters in this string. It differs from strlen in that it
+ only counts complete UTF-8 characters. Note, that this function
+ does not take combined characters into account. */
+size_t
+utf8_charcount (const char *s)
+{
+ size_t n;
+
+ for (n=0; *s; s++)
+ if ( (*s&0xc0) != 0x80 ) /* Exclude continuation bytes: 10xxxxxx */
+ n++;
+
+ return n;
+}
+
+
/****************************************************
********** W32 specific functions ****************
****************************************************/
Modified: trunk/jnlib/stringhelp.h
===================================================================
--- trunk/jnlib/stringhelp.h 2007-01-25 09:15:10 UTC (rev 4409)
+++ trunk/jnlib/stringhelp.h 2007-01-25 10:26:55 UTC (rev 4410)
@@ -57,6 +57,9 @@
char *sanitize_buffer (const void *p, size_t n, int delim);
+size_t utf8_charcount (const char *s);
+
+
#ifdef HAVE_W32_SYSTEM
const char *w32_strerror (int ec);
#endif
More information about the Gnupg-commits
mailing list