]> Sergey Matveev's repositories - meta4ra.git/commitdiff
OpenSSH signatures inclusion support v0.1.0
authorSergey Matveev <stargrave@stargrave.org>
Tue, 8 Aug 2023 12:09:31 +0000 (15:09 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Tue, 8 Aug 2023 14:27:45 +0000 (17:27 +0300)
cmd/meta4-check/main.go
cmd/meta4-create/main.go
common.go
scheme.go

index 45b08bdd6a0d446bf5e694627569a1ea7e24e30f..51338077e0289c8f23ef5350cd54f5f814ea3078 100644 (file)
@@ -49,10 +49,23 @@ func main() {
                        log.Fatalln(err)
                }
                for _, f := range meta.Files {
-                       if f.Signature != nil && *extractSig {
+                       for _, sig := range f.Signature {
+                               if !*extractSig {
+                                       continue
+                               }
+                               var fn string
+                               switch sig.MediaType {
+                               case meta4ra.SigMediaTypePGP:
+                                       fn = f.Name + ".asc"
+                               case meta4ra.SigMediaTypeSSH:
+                                       fn = f.Name + ".sig"
+                               }
+                               if fn == "" {
+                                       continue
+                               }
                                if err = os.WriteFile(
-                                       f.Name+".asc",
-                                       []byte(f.Signature.Signature),
+                                       fn,
+                                       []byte(strings.TrimPrefix(sig.Signature, "\n")),
                                        fs.FileMode(0666),
                                ); err != nil {
                                        fmt.Println("Error:", f.Name, "can not save signature:", err)
index f5d8b5ca4c98858ea3bc6812806534c944c34ec4..bd539b9edb998c1aae365e4fab127f3e34dbb76b 100644 (file)
@@ -36,7 +36,8 @@ func main() {
        fn := flag.String("fn", "", "Filename")
        mtime := flag.String("mtime", "", "Take that file's mtime as a Published date")
        desc := flag.String("desc", "", "Description")
-       sig := flag.String("sig", "", "Path to signature file")
+       sigPGP := flag.String("sig-pgp", "", "Path to OpenPGP .asc signature file")
+       sigSSH := flag.String("sig-ssh", "", "Path to OpenSSH .sig signature file")
        hashes := flag.String("hashes", strings.Join(meta4ra.HashesDefault, ","), "hash-name:command-s")
        torrent := flag.String("torrent", "", "Torrent URL")
        log.SetFlags(log.Lshortfile)
@@ -63,15 +64,25 @@ func main() {
                URLs:        urls,
                Hashes:      h.Sums(),
        }
-       if *sig != "" {
-               sigData, err := os.ReadFile(*sig)
+       if *sigPGP != "" {
+               sigData, err := os.ReadFile(*sigPGP)
                if err != nil {
                        log.Fatalln(err)
                }
-               f.Signature = &meta4ra.Signature{
-                       MediaType: meta4ra.GPGSigMediaType,
+               f.Signature = append(f.Signature, meta4ra.Signature{
+                       MediaType: meta4ra.SigMediaTypePGP,
                        Signature: "\n" + string(sigData),
+               })
+       }
+       if *sigSSH != "" {
+               sigData, err := os.ReadFile(*sigSSH)
+               if err != nil {
+                       log.Fatalln(err)
                }
+               f.Signature = append(f.Signature, meta4ra.Signature{
+                       MediaType: meta4ra.SigMediaTypeSSH,
+                       Signature: "\n" + string(sigData),
+               })
        }
        if *torrent != "" {
                f.MetaURLs = []meta4ra.MetaURL{{MediaType: "torrent", URL: *torrent}}
index a20c2439ced190e6bf3e325888a9f4c86080ce1f..dcd3e1634925bd25c139f5e82e6bcaa3b51463a6 100644 (file)
--- a/common.go
+++ b/common.go
@@ -19,6 +19,7 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 package meta4ra
 
 const (
-       Generator       = "meta4ra/0.3.0"
-       GPGSigMediaType = "application/pgp-signature"
+       Generator       = "meta4ra/0.4.0"
+       SigMediaTypePGP = "application/pgp-signature"
+       SigMediaTypeSSH = "application/ssh-signature"
 )
index b839282e77295ebd678da428d071f60a41502c16..6c37040c425c0fd9e9793e88b9b180134179c020 100644 (file)
--- a/scheme.go
+++ b/scheme.go
@@ -35,7 +35,7 @@ type File struct {
        Description string     `xml:"description,,omitempty"`
        Hashes      []Hash     `xml:"hash,,omitempty"`
        MetaURLs    []MetaURL  `xml:"metaurl,,omitempty"`
-       Signature   *Signature `xml:"signature"`
+       Signature   []Signature `xml:"signature"`
        Size        uint64     `xml:"size,,omitempty"`
        URLs        []URL      `xml:"url,,omitempty"`
 }