Key.hx 877 B

123456789101112131415161718192021222324252627282930313233343536
  1. package sys.ssl;
  2. import cpp.NativeSsl;
  3. private typedef PKEY = Dynamic;
  4. @:coreApi
  5. class Key {
  6. private var __k : PKEY;
  7. private function new( k : PKEY ){
  8. __k = k;
  9. }
  10. public static function loadFile( file : String, ?isPublic : Bool, ?pass : String ) : Key {
  11. var data = sys.io.File.getBytes( file );
  12. var str = cpp.Lib.stringReference(data);
  13. if( str.indexOf("-----BEGIN ") >= 0 )
  14. return readPEM( str, isPublic==true, pass );
  15. else
  16. return readDER( data, isPublic==true );
  17. }
  18. public static function readPEM( data : String, isPublic : Bool, ?pass : String ) : Key {
  19. return new Key( NativeSsl.key_from_pem( data, isPublic, pass ) );
  20. }
  21. public static function readDER( data : haxe.io.Bytes, isPublic : Bool ) : Key {
  22. return new Key( NativeSsl.key_from_der( data.getData(), isPublic ) );
  23. }
  24. static function __init__() : Void {
  25. NativeSsl.init();
  26. }
  27. }