A local copy of OpenSSL from GitHub
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.

100 lines
2.0 KiB

  1. /*
  2. * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the OpenSSL license (the "License"). You may not use
  5. * this file except in compliance with the License. You can obtain a copy
  6. * in the file LICENSE in the source distribution or at
  7. * https://www.openssl.org/source/license.html
  8. */
  9. #include <stdio.h>
  10. #include <errno.h>
  11. #include "bio_lcl.h"
  12. #include "internal/cryptlib.h"
  13. static int null_write(BIO *h, const char *buf, int num);
  14. static int null_read(BIO *h, char *buf, int size);
  15. static int null_puts(BIO *h, const char *str);
  16. static int null_gets(BIO *h, char *str, int size);
  17. static long null_ctrl(BIO *h, int cmd, long arg1, void *arg2);
  18. static int null_new(BIO *h);
  19. static int null_free(BIO *data);
  20. static const BIO_METHOD null_method = {
  21. BIO_TYPE_NULL,
  22. "NULL",
  23. null_write,
  24. null_read,
  25. null_puts,
  26. null_gets,
  27. null_ctrl,
  28. null_new,
  29. null_free,
  30. NULL,
  31. };
  32. const BIO_METHOD *BIO_s_null(void)
  33. {
  34. return (&null_method);
  35. }
  36. static int null_new(BIO *bi)
  37. {
  38. bi->init = 1;
  39. bi->num = 0;
  40. bi->ptr = (NULL);
  41. return (1);
  42. }
  43. static int null_free(BIO *a)
  44. {
  45. if (a == NULL)
  46. return (0);
  47. return (1);
  48. }
  49. static int null_read(BIO *b, char *out, int outl)
  50. {
  51. return (0);
  52. }
  53. static int null_write(BIO *b, const char *in, int inl)
  54. {
  55. return (inl);
  56. }
  57. static long null_ctrl(BIO *b, int cmd, long num, void *ptr)
  58. {
  59. long ret = 1;
  60. switch (cmd) {
  61. case BIO_CTRL_RESET:
  62. case BIO_CTRL_EOF:
  63. case BIO_CTRL_SET:
  64. case BIO_CTRL_SET_CLOSE:
  65. case BIO_CTRL_FLUSH:
  66. case BIO_CTRL_DUP:
  67. ret = 1;
  68. break;
  69. case BIO_CTRL_GET_CLOSE:
  70. case BIO_CTRL_INFO:
  71. case BIO_CTRL_GET:
  72. case BIO_CTRL_PENDING:
  73. case BIO_CTRL_WPENDING:
  74. default:
  75. ret = 0;
  76. break;
  77. }
  78. return (ret);
  79. }
  80. static int null_gets(BIO *bp, char *buf, int size)
  81. {
  82. return (0);
  83. }
  84. static int null_puts(BIO *bp, const char *str)
  85. {
  86. if (str == NULL)
  87. return (0);
  88. return (strlen(str));
  89. }