Translated using Weblate (Chinese (Simplified))
[cygwin-setup.git] / KeysSetting.h
blobf7b9336c8cbe67fdbcb95a4b30caa681178a59ba
1 /*
2 * Copyright (c) 2008, Dave Korn.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * A copy of the GNU General Public License can be found at
10 * http://www.gnu.org/
12 * This is the header for the ExtraKeysSetting class, which persists and reads
13 * in (and saves) extra public DSA signing keys for the verification process.
14 * It stores them all in a contiguous memory buffer. Each is one line of
15 * ASCII text terminated by LF. THERE IS NO NUL-TERMINATION HERE, TAKE CARE!
16 * The buffer is sized to the exact size of the content including the terminating
17 * LF of the last entry. There is no zero after it. After reading the file,
18 * any partial last line is truncated.
20 * Written by Dave Korn <dave.korn.cygwin@gmail.com>
24 #ifndef SETUP_KEYSSETTING_H
25 #define SETUP_KEYSSETTING_H
27 #include <string>
29 class ExtraKeysSetting
31 private:
32 char *keybuffer;
33 size_t bufsize;
34 size_t numkeys;
35 static ExtraKeysSetting *global;
36 public:
37 // Loads keys from the "extrakeys" user setting.
38 ExtraKeysSetting ();
39 // Saves them back again.
40 ~ExtraKeysSetting ();
41 static ExtraKeysSetting& instance () {return *global;}
43 private:
44 // Extend (or shrink) allocated buffer. Leaves it in a
45 // potentially invalid state until count_keys is called
46 // (or the bufsize is made valid by filling it up and
47 // the numkeys count adjusted likewise).
48 void realloc (size_t newbufsize);
49 // Count keys and size buffer after loading.
50 size_t count_keys (void);
51 // Add a key without testing for existence
52 void add_unique_key (const char *key);
54 public:
55 // Number of keys in buffer.
56 size_t num_keys (void);
57 // Get pointer to LF-terminated Nth. key string and len.
58 const char *get_key (size_t num, size_t *size);
59 // Add a key to the buffer (if not already present).
60 void add_key (const char *key);
61 // Empty the buffer.
62 void flush (void);
65 #endif /* SETUP_CONNECTIONSETTING_H */