Skip to content
Snippets Groups Projects
Select Git revision
  • 20b919b67b96b12a7357e28d401ce9cd1c0c9f28
  • master default protected
  • siv-mode
  • delete-des-compat
  • delete-rsa_blind
  • aes-struct-layout
  • master-updates
  • release-3.4-fixes
  • struct-layout
  • attribute-deprecated
  • rename-data-symbols
  • x86_64-sha_ni-sha256
  • ecc-params-tweak
  • delete-old-aes
  • cmac-support
  • x86_64-sha_ni-sha1
  • gcm-ctr-opt
  • ctr-opt
  • skein
  • api-opaque-fix
  • curve448
  • nettle_3.4.1_release_20181204
  • nettle_3.4.1rc1
  • nettle_3.4_release_20171119
  • nettle_3.4rc2
  • nettle_3.4rc1
  • nettle_3.3_release_20161001
  • nettle_3.2_release_20160128
  • nettle_3.1.1_release_20150424
  • nettle_3.1_release_20150407
  • nettle_3.1rc3
  • nettle_3.1rc2
  • nettle_3.1rc1
  • nettle_3.0_release_20140607
  • nettle_2.7.1_release_20130528
  • nettle_2.7_release_20130424
  • nettle_2.6_release_20130116
  • nettle_2.5_release_20120707
  • converted-master-branch-to-git
  • nettle_2.4_release_20110903
  • nettle_2.3_release_20110902
41 results

bignum.c

Blame
  • Forked from Nettle / nettle
    Source project has a limited visibility.
    Util.pmod 3.73 KiB
    #pike __REAL_VERSION__
    
    // This function will be easier to write in newer pikes, where there
    // will be a Image.ANY.decode function, but this will do for now. It
    // decoded an image from a string and returns a mapping with the
    // image, and optinally the alpha channel.
    // 
    // Currently supports most commonly used image formats, but only PNG
    // and GIF supports alpha channels
    //
    mapping low_decode_image(string data, mixed|void tocolor)
    {
      // NOTE: tocolor is ignored!
      return Image._decode( data );
    }
    
    
    // This function loads and decodes and image from disk.
    // Returns Image.image objects
    mapping low_load_image( string filename, mapping|array|void bgcol )
    {
      // NOTE: bgcol is ignored!
      return Image._load( filename );
    }
    
    //! Loads and decodes an image as a @[GDK1.Pixmap].
    //!
    //! @returns
    //! @mapping
    //!   @member string "format"
    //!     The MIME content type of the image.
    //!   @member GDK1.Bitmap "alpha"
    //!     The alpha channel of the image, if any. Otherwise @expr{0@}.
    //!   @member GDK1.Bitmap "img"
    //!     The decoded image.
    //! @endmapping
    mapping load_image( string filename, array|void bgcol )
    {
      if(mapping a = low_load_image( filename, bgcol ) )
      return ([
        "format":a->format,
        "alpha": a->alpha && GDK1.Bitmap( a->alpha ),
        "img":  GDK1.Pixmap( a->img ),
      ]);
    }
    
    //! Decodes an image as a @[GDK1.Pixmap].
    //!
    //! @returns
    //! @mapping
    //!   @member string "format"
    //!     The MIME content type of the image.
    //!   @member GDK1.Bitmap "alpha"
    //!     The alpha channel of the image, if any. Otherwise @expr{0@}.
    //!   @member GDK1.Bitmap "img"
    //!     The decoded image.
    //! @endmapping
    mapping decode_image( string data, mapping|array|void tocolor )
    {
      if(mapping a = low_decode_image( data,tocolor ) )
      return ([
        "format":a->format,
        "alpha": a->alpha && GDK1.Bitmap( a->alpha ),
        "img":   GDK1.Pixmap( a->img ),
      ]);
    }
    
    string low_encode_image( mapping img, string fmt )
    {
      if(img->alpha) return 0;
      catch {
        return Image[fmt||"PNG"]->encode( img->img );
      };
      return 0;
    }
    
    string encode_image( mapping img, string fmt )
    {
    }
    
    
    
    
    // Some shortcut handling stuff.
    
    mapping parse_shortcut_file( string f )
    {
      mapping ss = ([]);
      Stdio.File o = Stdio.File();
      if(o->open(f, "r"))
      {
        string p,k;
        foreach(o->read()/"\n", string l)
          if(sscanf(l, "\"%s\" \"%s\"", p, k) == 2)
    	ss[p] = k;
      }
      return ss;
    }
    
    void save_shortcut_file( string f, mapping ss )
    {
      Stdio.File o = Stdio.File();
      if(o->open(f, "wct"))
      {
        foreach(sort(indices(ss)), string s)
          o->write( "\""+s+"\" \""+ss[s]+"\"\n" );
      }
    }
    
    
    class signal_handling
    {
      class Fun
      {
        mixed arg;
        function tocall;
    
        void `()(mixed ... args)
        {
          array|int(1..1) err;
          if(!tocall)
            destruct();
          else
            if(err=catch(tocall(arg,@args)))
            {
              if(err == 1)
              {
                destruct();
                return;
              }
              werror("signal error: %s\n", describe_backtrace( err ) );
            }
        }
      
        void create(function f, mixed|void a)
        {
          tocall = f;
          arg = a;
        }
      }
    
      mapping signals = ([]);
      mapping r_signals = ([]);
    
      mixed signal_connect( string signal, function tocall, mixed|void arg )
      {
        object ret;
        if(signals[signal])
          signals[signal]+=({ (ret=Fun( tocall, arg)) });
        else
          signals[signal]=({ (ret=Fun( tocall, arg)) });
        r_signals[ret] = signal;
        return ret;
      }
    
      void signal_disconnect( Fun what )
      {
        if(r_signals[what])
        {
          signals[r_signals[what]] -= ({ what });
          m_delete( r_signals, what );
          destruct(what);
        }
      }
    
      void signal_broadcast( string signal, mixed ... args)
      {
        if(signals[signal]) 
        {
          signals[signal]-=({ 0 });
          signals[signal]( this, @args );
          signals[signal]-=({ 0 });
        }
      }
    }