You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

336 lines
10 KiB

  1. From 6f56ea4cfc52323002d818731a50a31e863b6843 Mon Sep 17 00:00:00 2001
  2. From: =?UTF-8?q?Nguy=E1=BB=85n=20H=E1=BB=93ng=20Qu=C3=A2n?=
  3. <ng.hong.quan@gmail.com>
  4. Date: Sun, 13 Jul 2014 19:41:36 +0800
  5. Subject: [PATCH 23/26] OpenPGP: Rename private "blob" type to avoid confusing
  6. with variable name.
  7. This name has been used for both data type and variable name of that
  8. type.
  9. ---
  10. src/libopensc/card-openpgp.c | 96 ++++++++++++++++++++++----------------------
  11. 1 file changed, 49 insertions(+), 47 deletions(-)
  12. Index: opensc-20150513/src/libopensc/card-openpgp.c
  13. ===================================================================
  14. --- opensc-20150513.orig/src/libopensc/card-openpgp.c
  15. +++ opensc-20150513/src/libopensc/card-openpgp.c
  16. @@ -113,9 +113,9 @@ enum _card_state {
  17. CARD_STATE_ACTIVATED = 0x05
  18. };
  19. -struct blob {
  20. - struct blob * next; /* pointer to next sibling */
  21. - struct blob * parent; /* pointer to parent */
  22. +typedef struct pgp_blob {
  23. + struct pgp_blob * next; /* pointer to next sibling */
  24. + struct pgp_blob * parent; /* pointer to parent */
  25. struct do_info *info;
  26. sc_file_t * file;
  27. @@ -124,8 +124,8 @@ struct blob {
  28. unsigned char * data;
  29. unsigned int len;
  30. - struct blob * files; /* pointer to 1st child */
  31. -};
  32. + struct pgp_blob * files; /* pointer to 1st child */
  33. +} pgp_blob_t;
  34. struct do_info {
  35. unsigned int id; /* ID of the DO in question */
  36. @@ -143,12 +143,12 @@ struct do_info {
  37. static int pgp_get_card_features(sc_card_t *card);
  38. static int pgp_finish(sc_card_t *card);
  39. -static void pgp_iterate_blobs(struct blob *, int, void (*func)());
  40. +static void pgp_iterate_blobs(pgp_blob_t *, int, void (*func)());
  41. -static int pgp_get_blob(sc_card_t *card, struct blob *blob,
  42. - unsigned int id, struct blob **ret);
  43. -static struct blob * pgp_new_blob(sc_card_t *, struct blob *, unsigned int, sc_file_t *);
  44. -static void pgp_free_blob(struct blob *);
  45. +static int pgp_get_blob(sc_card_t *card, pgp_blob_t *blob,
  46. + unsigned int id, pgp_blob_t **ret);
  47. +static pgp_blob_t * pgp_new_blob(sc_card_t *, pgp_blob_t *, unsigned int, sc_file_t *);
  48. +static void pgp_free_blob(pgp_blob_t *);
  49. static int pgp_get_pubkey(sc_card_t *, unsigned int,
  50. u8 *, size_t);
  51. static int pgp_get_pubkey_pem(sc_card_t *, unsigned int,
  52. @@ -274,8 +274,8 @@ static struct do_info pgp2_objects[] =
  53. #define DRVDATA(card) ((struct pgp_priv_data *) ((card)->drv_data))
  54. struct pgp_priv_data {
  55. - struct blob * mf;
  56. - struct blob * current; /* currently selected file */
  57. + pgp_blob_t * mf;
  58. + pgp_blob_t * current; /* currently selected file */
  59. enum _version bcd_version;
  60. struct do_info *pgp_objects;
  61. @@ -313,7 +313,7 @@ pgp_init(sc_card_t *card)
  62. sc_file_t *file = NULL;
  63. struct do_info *info;
  64. int r;
  65. - struct blob *child = NULL;
  66. + pgp_blob_t *child = NULL;
  67. LOG_FUNC_CALLED(card->ctx);
  68. @@ -397,7 +397,7 @@ pgp_get_card_features(sc_card_t *card)
  69. unsigned char *hist_bytes = card->atr.value;
  70. size_t atr_len = card->atr.len;
  71. size_t i = 0;
  72. - struct blob *blob, *blob6e, *blob73;
  73. + pgp_blob_t *blob, *blob6e, *blob73;
  74. /* parse card capabilities from historical bytes */
  75. while ((i < atr_len) && (hist_bytes[i] != 0x73))
  76. @@ -534,7 +534,7 @@ pgp_finish(sc_card_t *card)
  77. /* internal: fill a blob's data */
  78. static int
  79. -pgp_set_blob(struct blob *blob, const u8 *data, size_t len)
  80. +pgp_set_blob(pgp_blob_t *blob, const u8 *data, size_t len)
  81. {
  82. if (blob->data)
  83. free(blob->data);
  84. @@ -628,16 +628,16 @@ pgp_attach_acl(sc_card_t *card, sc_file_
  85. }
  86. /* internal: append a blob to the list of children of a given parent blob */
  87. -static struct blob *
  88. -pgp_new_blob(sc_card_t *card, struct blob *parent, unsigned int file_id,
  89. +static pgp_blob_t *
  90. +pgp_new_blob(sc_card_t *card, pgp_blob_t *parent, unsigned int file_id,
  91. sc_file_t *file)
  92. {
  93. - struct blob *blob = NULL;
  94. + pgp_blob_t *blob = NULL;
  95. if (file == NULL)
  96. return NULL;
  97. - if ((blob = calloc(1, sizeof(struct blob))) != NULL) {
  98. + if ((blob = calloc(1, sizeof(pgp_blob_t))) != NULL) {
  99. struct pgp_priv_data *priv = DRVDATA (card);
  100. struct do_info *info;
  101. @@ -651,7 +651,7 @@ pgp_new_blob(sc_card_t *card, struct blo
  102. blob->parent = parent;
  103. if (parent != NULL) {
  104. - struct blob **p;
  105. + pgp_blob_t **p;
  106. /* set file's path = parent's path + file's id */
  107. blob->file->path = parent->file->path;
  108. @@ -689,11 +689,11 @@ pgp_new_blob(sc_card_t *card, struct blo
  109. /* internal: free a blob including its content */
  110. static void
  111. -pgp_free_blob(struct blob *blob)
  112. +pgp_free_blob(pgp_blob_t *blob)
  113. {
  114. if (blob) {
  115. if (blob->parent) {
  116. - struct blob **p;
  117. + pgp_blob_t **p;
  118. /* remove blob from list of parent's children */
  119. for (p = &blob->parent->files; *p != NULL && *p != blob; p = &(*p)->next)
  120. @@ -713,14 +713,14 @@ pgp_free_blob(struct blob *blob)
  121. /* internal: iterate through the blob tree, calling a function for each blob */
  122. static void
  123. -pgp_iterate_blobs(struct blob *blob, int level, void (*func)())
  124. +pgp_iterate_blobs(pgp_blob_t *blob, int level, void (*func)())
  125. {
  126. if (blob) {
  127. if (level > 0) {
  128. - struct blob *child = blob->files;
  129. + pgp_blob_t *child = blob->files;
  130. while (child != NULL) {
  131. - struct blob *next = child->next;
  132. + pgp_blob_t *next = child->next;
  133. pgp_iterate_blobs(child, level-1, func);
  134. child = next;
  135. @@ -733,7 +733,7 @@ pgp_iterate_blobs(struct blob *blob, int
  136. /* internal: read a blob's contents from card */
  137. static int
  138. -pgp_read_blob(sc_card_t *card, struct blob *blob)
  139. +pgp_read_blob(sc_card_t *card, pgp_blob_t *blob)
  140. {
  141. struct pgp_priv_data *priv = DRVDATA (card);
  142. @@ -780,7 +780,7 @@ pgp_read_blob(sc_card_t *card, struct bl
  143. * The OpenPGP card has a TLV encoding according ASN.1 BER-encoding rules.
  144. */
  145. static int
  146. -pgp_enumerate_blob(sc_card_t *card, struct blob *blob)
  147. +pgp_enumerate_blob(sc_card_t *card, pgp_blob_t *blob)
  148. {
  149. const u8 *in;
  150. int r;
  151. @@ -797,7 +797,7 @@ pgp_enumerate_blob(sc_card_t *card, stru
  152. unsigned int cla, tag, tmptag;
  153. size_t len;
  154. const u8 *data = in;
  155. - struct blob *new;
  156. + pgp_blob_t *new;
  157. r = sc_asn1_read_tag(&data, blob->len - (in - blob->data),
  158. &cla, &tag, &len);
  159. @@ -827,10 +827,10 @@ pgp_enumerate_blob(sc_card_t *card, stru
  160. /* internal: find a blob by ID below a given parent, filling its contents when necessary */
  161. static int
  162. -pgp_get_blob(sc_card_t *card, struct blob *blob, unsigned int id,
  163. - struct blob **ret)
  164. +pgp_get_blob(sc_card_t *card, pgp_blob_t *blob, unsigned int id,
  165. + pgp_blob_t **ret)
  166. {
  167. - struct blob *child;
  168. + pgp_blob_t *child;
  169. int r;
  170. if ((r = pgp_enumerate_blob(card, blob)) < 0)
  171. @@ -866,10 +866,10 @@ pgp_get_blob(sc_card_t *card, struct blo
  172. /* Internal: search recursively for a blob by ID below a given root */
  173. static int
  174. -pgp_seek_blob(sc_card_t *card, struct blob *root, unsigned int id,
  175. - struct blob **ret)
  176. +pgp_seek_blob(sc_card_t *card, pgp_blob_t *root, unsigned int id,
  177. + pgp_blob_t **ret)
  178. {
  179. - struct blob *child;
  180. + pgp_blob_t *child;
  181. int r;
  182. if ((r = pgp_get_blob(card, root, id, ret)) == 0)
  183. @@ -891,11 +891,11 @@ pgp_seek_blob(sc_card_t *card, struct bl
  184. }
  185. /* internal: find a blob by tag - pgp_seek_blob with optimizations */
  186. -static struct blob *
  187. +static pgp_blob_t *
  188. pgp_find_blob(sc_card_t *card, unsigned int tag)
  189. {
  190. struct pgp_priv_data *priv = DRVDATA(card);
  191. - struct blob *blob = NULL;
  192. + pgp_blob_t *blob = NULL;
  193. int r;
  194. /* Check if current selected blob is which we want to test*/
  195. @@ -949,7 +949,7 @@ static int
  196. pgp_select_file(sc_card_t *card, const sc_path_t *path, sc_file_t **ret)
  197. {
  198. struct pgp_priv_data *priv = DRVDATA(card);
  199. - struct blob *blob;
  200. + pgp_blob_t *blob;
  201. unsigned int path_start = 0;
  202. unsigned int n;
  203. sc_path_t dummy_path;
  204. @@ -1030,7 +1030,7 @@ static int
  205. pgp_list_files(sc_card_t *card, u8 *buf, size_t buflen)
  206. {
  207. struct pgp_priv_data *priv = DRVDATA(card);
  208. - struct blob *blob;
  209. + pgp_blob_t *blob;
  210. unsigned int k;
  211. int r;
  212. @@ -1066,7 +1066,7 @@ pgp_read_binary(sc_card_t *card, unsigne
  213. u8 *buf, size_t count, unsigned long flags)
  214. {
  215. struct pgp_priv_data *priv = DRVDATA(card);
  216. - struct blob *blob;
  217. + pgp_blob_t *blob;
  218. int r;
  219. LOG_FUNC_CALLED(card->ctx);
  220. @@ -1142,7 +1142,7 @@ static int
  221. pgp_get_pubkey_pem(sc_card_t *card, unsigned int tag, u8 *buf, size_t buf_len)
  222. {
  223. struct pgp_priv_data *priv = DRVDATA(card);
  224. - struct blob *blob, *mod_blob, *exp_blob;
  225. + pgp_blob_t *blob, *mod_blob, *exp_blob;
  226. sc_pkcs15_pubkey_t pubkey;
  227. u8 *data;
  228. size_t len;
  229. @@ -1337,7 +1337,7 @@ static int
  230. pgp_put_data(sc_card_t *card, unsigned int tag, const u8 *buf, size_t buf_len)
  231. {
  232. struct pgp_priv_data *priv = DRVDATA(card);
  233. - struct blob *affected_blob = NULL;
  234. + pgp_blob_t *affected_blob = NULL;
  235. struct do_info *dinfo = NULL;
  236. int r;
  237. @@ -1611,7 +1611,7 @@ static int
  238. pgp_update_new_algo_attr(sc_card_t *card, sc_cardctl_openpgp_keygen_info_t *key_info)
  239. {
  240. struct pgp_priv_data *priv = DRVDATA(card);
  241. - struct blob *algo_blob;
  242. + pgp_blob_t *algo_blob;
  243. unsigned int old_modulus_len; /* Measured in bit */
  244. unsigned int old_exponent_len;
  245. const unsigned int tag = 0x00C0 | key_info->keytype;
  246. @@ -1716,7 +1716,7 @@ pgp_calculate_and_store_fingerprint(sc_c
  247. u8 *p; /* Use this pointer to set fp_buffer content */
  248. size_t pk_packet_len;
  249. unsigned int tag;
  250. - struct blob *fpseq_blob;
  251. + pgp_blob_t *fpseq_blob;
  252. u8 *newdata;
  253. int r;
  254. @@ -1805,7 +1805,7 @@ pgp_update_pubkey_blob(sc_card_t *card,
  255. u8* exponent, size_t exponent_len, u8 key_id)
  256. {
  257. struct pgp_priv_data *priv = DRVDATA(card);
  258. - struct blob *pk_blob;
  259. + pgp_blob_t *pk_blob;
  260. unsigned int blob_id;
  261. sc_pkcs15_pubkey_t pubkey;
  262. u8 *data = NULL;
  263. @@ -1947,6 +1947,8 @@ static int pgp_update_card_algorithms(sc
  264. **/
  265. static int pgp_gen_key(sc_card_t *card, sc_cardctl_openpgp_keygen_info_t *key_info)
  266. {
  267. + struct pgp_priv_data *priv = DRVDATA(card);
  268. + pgp_blob_t *algo_blob;
  269. sc_apdu_t apdu;
  270. /* Temporary variables to hold APDU params */
  271. u8 apdu_case;
  272. @@ -2143,7 +2145,7 @@ pgp_build_extended_header_list(sc_card_t
  273. };
  274. size_t comp_to_add = 3;
  275. size_t req_e_len = 0; /* The exponent length specified in Algorithm Attributes */
  276. - struct blob *alat_blob;
  277. + pgp_blob_t *alat_blob;
  278. u8 i;
  279. int r;
  280. @@ -2496,7 +2498,7 @@ static int
  281. pgp_delete_file(sc_card_t *card, const sc_path_t *path)
  282. {
  283. struct pgp_priv_data *priv = DRVDATA(card);
  284. - struct blob *blob;
  285. + pgp_blob_t *blob;
  286. sc_file_t *file;
  287. u8 key_id;
  288. int r;
  289. @@ -2546,7 +2548,7 @@ pgp_update_binary(sc_card_t *card, unsig
  290. const u8 *buf, size_t count, unsigned long flags)
  291. {
  292. struct pgp_priv_data *priv = DRVDATA(card);
  293. - struct blob *blob = priv->current;
  294. + pgp_blob_t *blob = priv->current;
  295. int r = SC_SUCCESS;
  296. LOG_FUNC_CALLED(card->ctx);