Context.hx 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package sys.ssl;
  2. private typedef ConfigPtr = hl.Abstract<"mbedtls_ssl_config">;
  3. private typedef ContextPtr = hl.Abstract<"mbedtls_ssl_context">;
  4. @:keep class SNICbResult {
  5. public var cert : Certificate.CertificatePtr;
  6. public var key : Key.KeyPtr;
  7. public function new( cert : Certificate, key : Key ){
  8. this.cert = @:privateAccess cert.__x;
  9. this.key = @:privateAccess key.__k;
  10. }
  11. }
  12. @:hlNative("ssl","ssl_")
  13. abstract Context(ContextPtr) {
  14. public function new(config) {
  15. this = ssl_new(config);
  16. }
  17. public function close() : Void {}
  18. public function handshake() : Int { return 0; }
  19. public function recvChar() : Int { return 0; }
  20. public function sendChar( c : Int ) : Int { return 0; }
  21. public function getPeerCertificate() : Certificate.CertificatePtr { return null; }
  22. public function recv( bytes : hl.Bytes, pos : Int, len : Int ) : Int { return 0; }
  23. public function send( bytes : hl.Bytes, pos : Int, len : Int ) : Int { return 0; }
  24. public function setSocket( socket : sys.net.Socket.SocketHandle ) : Void { }
  25. public function setHostname( name : hl.Bytes ) : Void { }
  26. @:hlNative("ssl","ssl_new") static function ssl_new( conf : Config ) : ContextPtr { return null; }
  27. }
  28. @:hlNative("ssl","conf_")
  29. abstract Config(ConfigPtr) {
  30. public function new( server : Bool ) {
  31. this = conf_new(server);
  32. }
  33. public function setCert( cert : Certificate.CertificatePtr, pkey : Key.KeyPtr ) : Void { }
  34. public function setCa( ca : Certificate.CertificatePtr ) : Void { }
  35. public function close() : Void { }
  36. public function setVerify( mode : Int ) : Void { }
  37. public function setServernameCallback( cb : hl.Bytes -> SNICbResult ) : Void { }
  38. @:hlNative("ssl","conf_new") static function conf_new( server : Bool ) : ConfigPtr { return null; }
  39. }