summaryrefslogtreecommitdiff
path: root/plugins/CryptoPP/src/GPGw/keys.c
blob: 4cfbe4f71d6043cd44034721488c24763c02c2cc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include "commonheaders.h"

typedef char tkeyuserid[keyuseridsize];

tkeyuserid *keyuserids[2];
int keyuseridcount[2];


void initKeyUserIDs(const int atype)
{
  keyuseridcount[atype]=0;
  keyuserids[atype]=NULL;
}


void updateKeyUserIDs(const int atype)
{
  char *pos;
  gpgResult gpgresult;
  char buffer[largebuffersize];
  char keyuserid[keyuseridsize];

  releaseKeyUserIDs(atype);
  initKeyUserIDs(atype);

  ZeroMemory(buffer, sizeof(buffer));
  if(atype==publickeyuserid) gpgresult=gpgListPublicKeys(buffer);
  else gpgresult=gpgListSecretKeys(buffer);

  if(gpgresult!=gpgSuccess)
  {
//    if(atype==publickeyuserid) ErrorMessage(txterror, txtlistpublickeysfailed, txtverifyoptions);
//    else ErrorMessage(txterror, txtlistsecretkeysfailed, txtverifyoptions);
    return;
  }

  for(pos=buffer; pos!=NULL; )
  {
    pos=getNextPart(keyuserid, pos, txtcrlf);

    if(pos!=NULL)
    {
      keyuseridcount[atype]++;
      keyuserids[atype]=realloc(keyuserids[atype], sizeof(tkeyuserid)*keyuseridcount[atype]);
      strcpy(keyuserids[atype][keyuseridcount[atype]-1], keyuserid);
    }
  }
}


void releaseKeyUserIDs(const int atype)
{
	free(keyuserids[atype]);
}


char *getKeyUserID(const int atype, const int aindex)
{
	return keyuserids[atype][aindex];
}


int getKeyUserIDCount(const int atype)
{
	return keyuseridcount[atype];
}