Commit a3784891 authored by zauberstuhl's avatar zauberstuhl

Append author signatures directly via a struct func

parent 45bd3737
...@@ -36,4 +36,8 @@ const ( ...@@ -36,4 +36,8 @@ const (
// webfinger // webfinger
WebFingerOstatus = "http://ostatus.org/schema/1.0/subscribe" WebFingerOstatus = "http://ostatus.org/schema/1.0/subscribe"
WebFingerHcard = "http://microformats.org/profile/hcard" WebFingerHcard = "http://microformats.org/profile/hcard"
// signature types
AuthorSignatureType = iota
ParentAuthorSignatureType
) )
...@@ -17,7 +17,10 @@ package federation ...@@ -17,7 +17,10 @@ package federation
// along with this program. If not, see <http://www.gnu.org/licenses/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
// //
import "encoding/xml" import (
"encoding/xml"
"errors"
)
type EntityComment struct { type EntityComment struct {
XMLName xml.Name `xml:"comment"` XMLName xml.Name `xml:"comment"`
...@@ -33,3 +36,19 @@ type EntityComment struct { ...@@ -33,3 +36,19 @@ type EntityComment struct {
func (e *EntityComment) SignatureOrder() string { func (e *EntityComment) SignatureOrder() string {
return "author created_at guid parent_guid text" return "author created_at guid parent_guid text"
} }
func (e *EntityComment) AppendSignature(privKey, order string, typ int) error {
signature, err := AuthorSignature(*e, order, privKey)
if err != nil {
return err
}
if AuthorSignatureType == typ {
(*e).AuthorSignature = signature
} else if ParentAuthorSignatureType == typ {
(*e).ParentAuthorSignature = signature
} else {
return errors.New("Unsupported author signature type!")
}
return nil
}
...@@ -17,7 +17,10 @@ package federation ...@@ -17,7 +17,10 @@ package federation
// along with this program. If not, see <http://www.gnu.org/licenses/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
// //
import "encoding/xml" import (
"encoding/xml"
"errors"
)
type EntityLike struct { type EntityLike struct {
XMLName xml.Name `xml:"like"` XMLName xml.Name `xml:"like"`
...@@ -33,3 +36,19 @@ type EntityLike struct { ...@@ -33,3 +36,19 @@ type EntityLike struct {
func (e *EntityLike) SignatureOrder() string { func (e *EntityLike) SignatureOrder() string {
return "positive guid parent_guid target_type author" return "positive guid parent_guid target_type author"
} }
func (e *EntityLike) AppendSignature(privKey, order string, typ int) error {
signature, err := AuthorSignature(*e, privKey, order)
if err != nil {
return err
}
if AuthorSignatureType == typ {
(*e).AuthorSignature = signature
} else if ParentAuthorSignatureType == typ {
(*e).ParentAuthorSignature = signature
} else {
return errors.New("Unsupported author signature type!")
}
return nil
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment