generated from TBD54566975/tbd-project-template
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6888452
commit e0e2549
Showing
2 changed files
with
43 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
|
||
"github.com/tbd54566975/web5-go/jwt" | ||
) | ||
|
||
type jwtVerifyCMD struct { | ||
JWT string `arg:"" help:"The base64 encoded JWT"` | ||
Claims bool `help:"Only print the JWT Claims." default:"false"` | ||
NoIndent bool `help:"Print the decoded VC-JWT without indentation." default:"false"` | ||
} | ||
|
||
func (c *jwtVerifyCMD) Run() error { | ||
decoded, err := jwt.Verify(c.JWT) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
var partToPrint any | ||
if c.Claims { | ||
partToPrint = decoded.Claims | ||
} else { | ||
partToPrint = decoded | ||
} | ||
|
||
var bytes []byte | ||
if c.NoIndent { | ||
bytes, err = json.Marshal(partToPrint) | ||
} else { | ||
bytes, err = json.MarshalIndent(partToPrint, "", " ") | ||
} | ||
if err != nil { | ||
return err | ||
} | ||
|
||
fmt.Println(string(bytes)) | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters