tor  0.4.1.0-alpha-dev
nickname.c
Go to the documentation of this file.
1 /* Copyright (c) 2001 Matej Pfajfar.
2  * Copyright (c) 2001-2004, Roger Dingledine.
3  * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
4  * Copyright (c) 2007-2019, The Tor Project, Inc. */
5 /* See LICENSE for licensing information */
6 
12 #include "core/or/or.h"
14 
18 int
19 is_legal_nickname(const char *s)
20 {
21  size_t len;
22  tor_assert(s);
23  len = strlen(s);
24  return len > 0 && len <= MAX_NICKNAME_LEN &&
25  strspn(s,LEGAL_NICKNAME_CHARACTERS) == len;
26 }
27 
30 int
32 {
33  if (*s!='$')
34  return is_legal_nickname(s);
35  else
36  return is_legal_hexdigest(s);
37 }
38 
44 int
45 is_legal_hexdigest(const char *s)
46 {
47  size_t len;
48  tor_assert(s);
49  if (s[0] == '$') s++;
50  len = strlen(s);
51  if (len > HEX_DIGEST_LEN) {
52  if (s[HEX_DIGEST_LEN] == '=' ||
53  s[HEX_DIGEST_LEN] == '~') {
55  return 0;
56  } else {
57  return 0;
58  }
59  }
60  return (len >= HEX_DIGEST_LEN &&
61  strspn(s,HEX_CHARACTERS)==HEX_DIGEST_LEN);
62 }
#define MAX_NICKNAME_LEN
Definition: or.h:113
Header file for nickname.c.
int is_legal_nickname_or_hexdigest(const char *s)
Definition: nickname.c:31
#define LEGAL_NICKNAME_CHARACTERS
Definition: or.h:552
int is_legal_hexdigest(const char *s)
Definition: nickname.c:45
tor_assert(buffer)
Master header file for Tor-specific functionality.
int is_legal_nickname(const char *s)
Definition: nickname.c:19
#define HEX_DIGEST_LEN
Definition: crypto_digest.h:35
#define HEX_CHARACTERS
Definition: util_string.h:28