Coverage Report

Created: 2025-10-10 06:21

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/strongswan/src/libstrongswan/credentials/keys/private_key.c
Line
Count
Source
1
/*
2
 * Copyright (C) 2007 Martin Willi
3
 *
4
 * Copyright (C) secunet Security Networks AG
5
 *
6
 * This program is free software; you can redistribute it and/or modify it
7
 * under the terms of the GNU General Public License as published by the
8
 * Free Software Foundation; either version 2 of the License, or (at your
9
 * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
10
 *
11
 * This program is distributed in the hope that it will be useful, but
12
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14
 * for more details.
15
 */
16
17
#include "private_key.h"
18
19
/**
20
 * See header.
21
 */
22
bool private_key_equals(private_key_t *this, private_key_t *other)
23
0
{
24
0
  cred_encoding_type_t type;
25
0
  chunk_t a, b;
26
27
0
  if (this == other)
28
0
  {
29
0
    return TRUE;
30
0
  }
31
32
0
  for (type = 0; type < CRED_ENCODING_MAX; type++)
33
0
  {
34
0
    if (this->get_fingerprint(this, type, &a) &&
35
0
      other->get_fingerprint(other, type, &b))
36
0
    {
37
0
      return chunk_equals(a, b);
38
0
    }
39
0
  }
40
0
  return FALSE;
41
0
}
42
43
/**
44
 * See header.
45
 */
46
bool private_key_belongs_to(private_key_t *private, public_key_t *public)
47
0
{
48
0
  cred_encoding_type_t type;
49
0
  chunk_t a, b;
50
51
0
  for (type = 0; type < CRED_ENCODING_MAX; type++)
52
0
  {
53
0
    if (private->get_fingerprint(private, type, &a) &&
54
0
      public->get_fingerprint(public, type, &b))
55
0
    {
56
0
      return chunk_equals(a, b);
57
0
    }
58
0
  }
59
0
  return FALSE;
60
0
}
61
62
/**
63
 * See header.
64
 */
65
bool private_key_has_fingerprint(private_key_t *private, chunk_t fingerprint)
66
0
{
67
0
  cred_encoding_type_t type;
68
0
  chunk_t current;
69
70
0
  for (type = 0; type < KEYID_MAX; type++)
71
0
  {
72
0
    if (private->get_fingerprint(private, type, &current) &&
73
0
      chunk_equals(current, fingerprint))
74
0
    {
75
0
      return TRUE;
76
0
    }
77
0
  }
78
0
  return FALSE;
79
0
}
80