Context.hx 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. * Copyright (C)2005-2019 Haxe Foundation
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  20. * DEALINGS IN THE SOFTWARE.
  21. */
  22. package sys.ssl;
  23. private typedef ConfigPtr = hl.Abstract<"mbedtls_ssl_config">;
  24. private typedef ContextPtr = hl.Abstract<"mbedtls_ssl_context">;
  25. @:keep class SNICbResult {
  26. public var cert:Certificate.CertificatePtr;
  27. public var key:Key.KeyPtr;
  28. public function new(cert:Certificate, key:Key) {
  29. this.cert = @:privateAccess cert.__x;
  30. this.key = @:privateAccess key.__k;
  31. }
  32. }
  33. @:hlNative("ssl", "ssl_")
  34. abstract Context(ContextPtr) {
  35. public function new(config) {
  36. this = ssl_new(config);
  37. }
  38. public function close():Void {}
  39. public function handshake():Int {
  40. return 0;
  41. }
  42. public function recvChar():Int {
  43. return 0;
  44. }
  45. public function sendChar(c:Int):Int {
  46. return 0;
  47. }
  48. public function getPeerCertificate():Certificate.CertificatePtr {
  49. return null;
  50. }
  51. public function recv(bytes:hl.Bytes, pos:Int, len:Int):Int {
  52. return 0;
  53. }
  54. public function send(bytes:hl.Bytes, pos:Int, len:Int):Int {
  55. return 0;
  56. }
  57. public function setSocket(socket:sys.net.Socket.SocketHandle):Void {}
  58. public function setBio( ctx : Dynamic ) {}
  59. public function setHostname(name:hl.Bytes):Void {}
  60. @:hlNative("ssl", "ssl_new") static function ssl_new(conf:Config):ContextPtr {
  61. return null;
  62. }
  63. }
  64. @:hlNative("ssl", "conf_")
  65. abstract Config(ConfigPtr) {
  66. public function new(server:Bool) {
  67. this = conf_new(server);
  68. }
  69. public function setCert(cert:Certificate.CertificatePtr, pkey:Key.KeyPtr):Void {}
  70. public function setCa(ca:Certificate.CertificatePtr):Void {}
  71. public function close():Void {}
  72. public function setVerify(mode:Int):Void {}
  73. public function setServernameCallback(cb:hl.Bytes->SNICbResult):Void {}
  74. @:hlNative("ssl", "conf_new") static function conf_new(server:Bool):ConfigPtr {
  75. return null;
  76. }
  77. }