package whisper import ( "crypto/ecdsa" "encoding/binary" "fmt" "time" "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/ethutil" "github.com/ethereum/go-ethereum/rlp" "github.com/obscuren/ecies" ) const ( DefaultPow = 50 * time.Millisecond ) type Envelope struct { Expiry uint32 // Whisper protocol specifies int32, really should be int64 Ttl uint32 // ^^^^^^ Topics [][]byte Data []byte Nonce uint32 hash Hash } func (self *Envelope) Hash() Hash { if self.hash == EmptyHash { self.hash = H(crypto.Sha3(ethutil.Encode(self))) } return self.hash } func NewEnvelope(ttl time.Duration, topics [][]byte, data *Message) *Envelope { exp := time.Now().Add(ttl) return &Envelope{uint32(exp.Unix()), uint32(ttl.Seconds()), topics, data.Bytes(), 0, Hash{}} } func (self *Envelope) Seal(pow time.Duration) { self.proveWork(pow) } func (self *Envelope) Open(prv *ecdsa.PrivateKey) (msg *Message, err error) { data := self.Data var message Message dataStart := 1 if data[0] > 0 { if len(data) < 66 { return nil, fmt.Errorf("unable to open envelope. First bit set but len(data) < 66") } dataStart = 66 message.Flags = data[0] message.Signature = data[1:66] } payload := data[dataStart:] if prv != nil { message.Payload, err = crypto.Decrypt(prv, payload) switch err { case nil: // OK case ecies.ErrInvalidPublicKey: // Payload isn't encrypted message.Payload = payload return &message, err default: return nil, fmt.Errorf("unable to open envelope. Decrypt failed: %v", err) } } return &message, nil } func (self *Envelope) proveWork(dura time.Duration) { var bestBit int d := make([]byte, 64) copy(d[:32], ethutil.Encode(self.withoutNonce())) then := time.Now().Add(dura).UnixNano() for n := uint32(0); time.Now().UnixNano() < then; { for i := 0; i < 1024; i++ { binary.BigEndian.PutUint32(d[60:], n) fbs := ethutil.FirstBitSet(ethutil.BigD(crypto.Sha3(d))) if fbs > bestBit { bestBit = fbs self.Nonce = n } n++ } } } func (self *Envelope) valid() bool { d := make([]byte, 64) copy(d[:32], ethutil.Encode(self.withoutNonce())) binary.BigEndian.PutUint32(d[60:], self.Nonce) return ethutil.FirstBitSet(ethutil.BigD(crypto.Sha3(d))) > 0 } func (self *Envelope) withoutNonce() interface{} { return []interface{}{self.Expiry, self.Ttl, ethutil.ByteSliceToInterface(self.Topics), self.Data} } func (self *Envelope) RlpData() interface{} { return []interface{}{self.Expiry, self.Ttl, ethutil.ByteSliceToInterface(self.Topics), self.Data, self.Nonce} } func (self *Envelope) DecodeRLP(s *rlp.Stream) error { var extenv struct { Expiry uint32 Ttl uint32 Topics [][]byte Data []byte Nonce uint32 } if err := s.Decode(&extenv); err != nil { return err } self.Expiry = extenv.Expiry self.Ttl = extenv.Ttl self.Topics = extenv.Topics self.Data = extenv.Data self.Nonce = extenv.Nonce // TODO We should use the stream directly here. self.hash = H(crypto.Sha3(ethutil.Encode(self))) return nil } 14Q2 FreeBSD Ports (https://github.com/freebsd/freebsd-ports)
aboutsummaryrefslogtreecommitdiffstats
path: root/japanese
Commit message (Collapse)AuthorAgeFilesLines
* - Add another MASTER_SITE, ftp.sra.co.jp is a little choosy.Munechika SUMIKAWA2003-04-211-1/+3
| | | | | | | | | | - Suppress a warning of configure. PR: ports/49075 Submitted by: Kazu TAKAMUNE <takamune@avrl.mei.co.jp> Notes: svn path=/head/; revision=79393
* Remove USE_GNOMENG.Joe Marcus Clarke2003-04-2110-10/+0
| | | | Notes: svn path=/head/; revision=79368
* Update lang/ruby, lang/ruby-devel and lang/ruby16-shim-ruby18 to theAkinori MUSHA2003-04-191-1/+1
| | | | | | | | | | latest snapshots as of 2003-04-19. ruby-bigdecimal (formerly known as ruby-bigfloat) and ruby-zlib are now part of ruby 1.8. Notes: svn path=/head/; revision=79296
* Location of japanese help was changed.Maho Nakata2003-04-172-6/+4
| | | | Notes: svn path=/head/; revision=79137
* Added Japanese localized version of OpenOffice.org 644m7 port.Maho Nakata2003-04-173-0/+35
| | | | | | | Slave port of editors/openoffice-devel. Notes: svn path=/head/; revision=79132
* Reflect the change in the ja-ptex-base's handling of texmf.cnf.Masafumi Max NAKANE2003-04-174-29/+8
| | | | | | | Add missing entry to the plist. Notes: svn path=/head/; revision=79119
* Correctly specify the shared lib no. of libt1 in LIB_DEPENDS.Masafumi Max NAKANE2003-04-175-35/+79
| | | | | | | | | | | | | | | | | | | | Pointed-Out by: SHIMURA Tatsuya <shimura@math.cst.nihon-u.ac.jp>, ITO Tsuyoshi <tsuyoshi@is.s.u-tokyo.ac.jp> Run mktexlsr at installation time since there can be a situation where only this port amongst other TeX related ports is upgraded. Remove some garbage from pkg-message Pointed-Out by: SHIOZAKI Takehiko <st@be.to> Don't install bin/{tftopl,pltotf} since modified version of them are installed by ja-ptex. Work-around to make portupgrade users happy, by making share/texmf/dvipdfm and share/texmf/web2c/texmf.cnf symbolic links. Since share/texmf/ls-R is updated by other ports, don't list them in the plist. Notes: svn path=/head/; revision=79118
* Fix the dependencies after the upgrade of japanese/ptex.Masafumi Max NAKANE2003-04-1611-16/+16
| | | | | | | | I am committing this since the maintainer did not respond to my request to check on this problem in past two days, this can be a temporary fix. Submitted by: Harold Gutch <logix@foobar.franken.de> Notes: svn path=/head/; revision=79054
* Correct the dependency after the name change of japanese/ptex*.Masafumi Max NAKANE2003-04-151-1/+1
| | | | | | | Submitted by: maintainer Notes: svn path=/head/; revision=78998
* Ah, I meant to make EUC the default kanji code.Masafumi Max NAKANE2003-04-141-1/+1
| | | | Notes: svn path=/head/; revision=78932
* Ooops, forgot to update the message file.Masafumi Max NAKANE2003-04-142-12/+8
| | | | Notes: svn path=/head/; revision=78931
* Upgrade to 3.1.2.Masafumi Max NAKANE2003-04-1435-11016/+4233
| | | | | | | | | | Now charset to be used can be specified at runtime, instead of compile time. Due to this change, charset specific ports are being removed, and pTeX now consists of two ports: ptex-base and ptex. Ptex-base is what used to be ptex-common, which installs non-Japanese portion of the system, and ptex is what used to be the charset specific portion, which installs Japanese specific files. Thus, ptex-common and ptex-euc are renamed to ptex-base and ptex respectively, and ptex-jis and ptex-sjis are being removed. Notes: svn path=/head/; revision=78929
* Because of security vulnerability and no maintaince, so remove this port.Norikatsu Shigemura2003-04-1318-1680/+0
| | | | | | | | PR: ports-jp/13641 Submitted by: NAKAJI Hiroyuki <nakaji@tutrp.tut.ac.jp> (maintainer) Notes: svn path=/head/; revision=78814
* Add gauche-kakasi 0.0, kAKASI binding for Gauche.Norikatsu Shigemura2003-04-135-0/+51