libssh2_publickey.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /* Copyright (C) Sara Golemon <sarag@libssh2.org>
  2. * All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms,
  5. * with or without modification, are permitted provided
  6. * that the following conditions are met:
  7. *
  8. * Redistributions of source code must retain the above
  9. * copyright notice, this list of conditions and the
  10. * following disclaimer.
  11. *
  12. * Redistributions in binary form must reproduce the above
  13. * copyright notice, this list of conditions and the following
  14. * disclaimer in the documentation and/or other materials
  15. * provided with the distribution.
  16. *
  17. * Neither the name of the copyright holder nor the names
  18. * of any other contributors may be used to endorse or
  19. * promote products derived from this software without
  20. * specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  23. * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  24. * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  25. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  26. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  27. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  28. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  29. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  30. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  31. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  32. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  33. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  34. * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
  35. * OF SUCH DAMAGE.
  36. */
  37. /* Note: This include file is only needed for using the
  38. * publickey SUBSYSTEM which is not the same as publickey
  39. * authentication. For authentication you only need libssh2.h
  40. *
  41. * For more information on the publickey subsystem,
  42. * refer to IETF draft: secsh-publickey
  43. *
  44. * SPDX-License-Identifier: BSD-3-Clause
  45. */
  46. #ifndef LIBSSH2_PUBLICKEY_H
  47. #define LIBSSH2_PUBLICKEY_H 1
  48. #include "libssh2.h"
  49. typedef struct _LIBSSH2_PUBLICKEY LIBSSH2_PUBLICKEY;
  50. typedef struct _libssh2_publickey_attribute {
  51. const char *name;
  52. unsigned long name_len;
  53. const char *value;
  54. unsigned long value_len;
  55. char mandatory;
  56. } libssh2_publickey_attribute;
  57. typedef struct _libssh2_publickey_list {
  58. unsigned char *packet; /* For freeing */
  59. const unsigned char *name;
  60. unsigned long name_len;
  61. const unsigned char *blob;
  62. unsigned long blob_len;
  63. unsigned long num_attrs;
  64. libssh2_publickey_attribute *attrs; /* free me */
  65. } libssh2_publickey_list;
  66. /* Generally use the first macro here, but if both name and value are string
  67. literals, you can use _fast() to take advantage of preprocessing */
  68. #define libssh2_publickey_attribute(name, value, mandatory) \
  69. { (name), strlen(name), (value), strlen(value), (mandatory) },
  70. #define libssh2_publickey_attribute_fast(name, value, mandatory) \
  71. { (name), sizeof(name) - 1, (value), sizeof(value) - 1, (mandatory) },
  72. #ifdef __cplusplus
  73. extern "C" {
  74. #endif
  75. /* Publickey Subsystem */
  76. LIBSSH2_API LIBSSH2_PUBLICKEY *
  77. libssh2_publickey_init(LIBSSH2_SESSION *session);
  78. LIBSSH2_API int
  79. libssh2_publickey_add_ex(LIBSSH2_PUBLICKEY *pkey,
  80. const unsigned char *name,
  81. unsigned long name_len,
  82. const unsigned char *blob,
  83. unsigned long blob_len, char overwrite,
  84. unsigned long num_attrs,
  85. const libssh2_publickey_attribute attrs[]);
  86. #define libssh2_publickey_add(pkey, name, blob, blob_len, overwrite, \
  87. num_attrs, attrs) \
  88. libssh2_publickey_add_ex((pkey), \
  89. (name), strlen(name), \
  90. (blob), (blob_len), \
  91. (overwrite), (num_attrs), (attrs))
  92. LIBSSH2_API int libssh2_publickey_remove_ex(LIBSSH2_PUBLICKEY *pkey,
  93. const unsigned char *name,
  94. unsigned long name_len,
  95. const unsigned char *blob,
  96. unsigned long blob_len);
  97. #define libssh2_publickey_remove(pkey, name, blob, blob_len) \
  98. libssh2_publickey_remove_ex((pkey), \
  99. (name), strlen(name), \
  100. (blob), (blob_len))
  101. LIBSSH2_API int
  102. libssh2_publickey_list_fetch(LIBSSH2_PUBLICKEY *pkey,
  103. unsigned long *num_keys,
  104. libssh2_publickey_list **pkey_list);
  105. LIBSSH2_API void
  106. libssh2_publickey_list_free(LIBSSH2_PUBLICKEY *pkey,
  107. libssh2_publickey_list *pkey_list);
  108. LIBSSH2_API int libssh2_publickey_shutdown(LIBSSH2_PUBLICKEY *pkey);
  109. #ifdef __cplusplus
  110. } /* extern "C" */
  111. #endif
  112. #endif /* LIBSSH2_PUBLICKEY_H */