//Update the named content func (t Tag) Update(hashBytes HID, typeString string) Tag { t.Parents = Parents{t.Hash()} t.HashBytes = hashBytes t.TypeString = typeString //t.nameSegment = t.nameSegment t.Version = newVersion() //t.hkid = t.hkid prikey, err := geterPoster.getPrivateKeyForHkid(t.Hkid) if err != nil { log.Panic("You don't seem to own this Domain") } ObjectHash := t.genTagHash( t.HashBytes, t.TypeString, t.NameSegment, t.Version, t.Parents, t.Hkid, ) ecdsaprikey := ecdsa.PrivateKey(*prikey) r, s, _ := ecdsa.Sign(rand.Reader, &ecdsaprikey, ObjectHash) t.Signature = elliptic.Marshal(elliptic.P521(), r, s) return t }
//NewTag build a new tag with the initial content func NewTag( HashBytes HID, TypeString string, nameSegment string, tparent Parents, hkid HKID, ) Tag { prikey, _ := geterPoster.getPrivateKeyForHkid(hkid) version := newVersion() if tparent == nil { tparent = Parents{Blob{}.Hash()} } ObjectHash := Tag{}.genTagHash( HashBytes, TypeString, nameSegment, version, tparent, hkid, ) ecdsaprikey := ecdsa.PrivateKey(*prikey) r, s, _ := ecdsa.Sign(rand.Reader, &ecdsaprikey, ObjectHash) signature := elliptic.Marshal(elliptic.P521(), r, s) t := Tag{HashBytes, TypeString, nameSegment, version, tparent, hkid, signature} return t }
//Verify returns true if PrivateKey and PrivateKey are a pair. func (p PrivateKey) Verify() bool { ObjectHash := make([]byte, 32) _, err := rand.Read(ObjectHash) if err != nil { fmt.Println("error:", err) } prikey := ecdsa.PrivateKey(p) r, s, err := ecdsa.Sign(rand.Reader, &prikey, ObjectHash) return ecdsa.Verify(&p.PublicKey, ObjectHash, r, s) }
func (c Commit) commitSign(listHash []byte, version int64, cparents Parents, hkid []byte) (signature []byte) { ObjectHash := c.genCommitHash(listHash, version, cparents, hkid) prikey, err := geterPoster.getPrivateKeyForHkid(hkid) ecdsaprikey := ecdsa.PrivateKey(*prikey) r, s, err := ecdsa.Sign(rand.Reader, &ecdsaprikey, ObjectHash) if err != nil { log.Panic(err) } signature = elliptic.Marshal(prikey.PublicKey.Curve, r, s) return }
//Bytes returns the marshaled public key as a slice of byte. func (p PrivateKey) Bytes() []byte { return ecdsa.PrivateKey(p).D.Bytes() }
func NewDString() string { newKey := KeyGen() intd := ecdsa.PrivateKey(*newKey).D keyString := fmt.Sprintf("%v", intd) return keyString }