192 lines
12 KiB
HTML
192 lines
12 KiB
HTML
<html>
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
|
<link rel="stylesheet" href="../../coverage.css"/> <title> dog_and_duck/scratch/scratch.clj </title>
|
|
</head>
|
|
<body>
|
|
<span class="covered" title="1 out of 1 forms covered">
|
|
001 (ns dog-and-duck.scratch.scratch
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
002 "Scratchpad where I try to understand how to do this stuff."
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
003 (:require [clj-activitypub.core :as activitypub]
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
004 [clj-activitypub.webfinger :as webfinger]
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
005 [clj-pgp.core :as pgp]
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
006 [clj-pgp.keyring :as keyring]
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
007 [clj-pgp.generate :as pgp-gen]
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
008 [clojure.walk :refer [keywordize-keys]]
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
009 [clojure.pprint :refer [pprint]]))
|
|
</span><br/>
|
|
<span class="blank" title="0 out of 0 forms covered">
|
|
010
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
011 ;;; Copyright (C) Simon Brooke, 2022
|
|
</span><br/>
|
|
<span class="blank" title="0 out of 0 forms covered">
|
|
012
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
013 ;;; This program is free software; you can redistribute it and/or
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
014 ;;; modify it under the terms of the GNU General Public License
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
015 ;;; as published by the Free Software Foundation; either version 2
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
016 ;;; of the License, or (at your option) any later version.
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
017
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
018 ;;; This program is distributed in the hope that it will be useful,
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
019 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
020 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
021 ;;; GNU General Public License for more details.
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
022
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
023 ;;; You should have received a copy of the GNU General Public License
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
024 ;;; along with this program; if not, write to the Free Software
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
025 ;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
</span><br/>
|
|
<span class="blank" title="0 out of 0 forms covered">
|
|
026
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
027 ;;; Use any ActivityPub account handle you like - for example, your own
|
|
</span><br/>
|
|
<span class="covered" title="2 out of 2 forms covered">
|
|
028 (def account-handle "@simon_brooke@mastodon.scot")
|
|
</span><br/>
|
|
<span class="blank" title="0 out of 0 forms covered">
|
|
029
|
|
</span><br/>
|
|
<span class="covered" title="4 out of 4 forms covered">
|
|
030 (def handle (activitypub/parse-account account-handle))
|
|
</span><br/>
|
|
<span class="covered" title="4 out of 4 forms covered">
|
|
031 (webfinger/fetch-user-id "mastodon.scot" "simon_brooke")
|
|
</span><br/>
|
|
<span class="covered" title="9 out of 9 forms covered">
|
|
032 (apply webfinger/fetch-user-id (map handle [:domain :username]))
|
|
</span><br/>
|
|
<span class="blank" title="0 out of 0 forms covered">
|
|
033
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
034 ;;; Retrieve the account details from its home server
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
035 ;;; (`keywordize-keys` is not necessary here but produces a more idiomatic clojure
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
036 ;;; data structure)
|
|
</span><br/>
|
|
<span class="covered" title="1 out of 1 forms covered">
|
|
037 (def account
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
038 "Fetch my account to mess with"
|
|
</span><br/>
|
|
<span class="covered" title="4 out of 4 forms covered">
|
|
039 (let [handle (activitypub/parse-account account-handle)]
|
|
</span><br/>
|
|
<span class="covered" title="2 out of 2 forms covered">
|
|
040 (keywordize-keys
|
|
</span><br/>
|
|
<span class="covered" title="2 out of 2 forms covered">
|
|
041 (activitypub/fetch-user
|
|
</span><br/>
|
|
<span class="covered" title="9 out of 9 forms covered">
|
|
042 (apply webfinger/fetch-user-id (map handle [:domain :username]))))))
|
|
</span><br/>
|
|
<span class="blank" title="0 out of 0 forms covered">
|
|
043
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
044 ;;; examine what you got back!
|
|
</span><br/>
|
|
<span class="covered" title="3 out of 3 forms covered">
|
|
045 (:inbox account)
|
|
</span><br/>
|
|
<span class="blank" title="0 out of 0 forms covered">
|
|
046
|
|
</span><br/>
|
|
<span class="blank" title="0 out of 0 forms covered">
|
|
047
|
|
</span><br/>
|
|
<span class="covered" title="4 out of 4 forms covered">
|
|
048 (def rsa (pgp-gen/rsa-keypair-generator 2048))
|
|
</span><br/>
|
|
<span class="covered" title="5 out of 5 forms covered">
|
|
049 (def kp (pgp-gen/generate-keypair rsa :rsa-general))
|
|
</span><br/>
|
|
<span class="blank" title="0 out of 0 forms covered">
|
|
050
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
051 ;; how we make a public/private key pair. But this key pair is not the one
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
052 ;; known to mastodon.scot as my key pair, so that doesn't get us very far...
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
053 ;; I think.
|
|
</span><br/>
|
|
<span class="covered" title="4 out of 4 forms covered">
|
|
054 (let [rsa (pgp-gen/rsa-keypair-generator 2048)
|
|
</span><br/>
|
|
<span class="covered" title="4 out of 4 forms covered">
|
|
055 kp (pgp-gen/generate-keypair rsa :rsa-general)
|
|
</span><br/>
|
|
<span class="covered" title="2 out of 2 forms covered">
|
|
056 public (-> kp .getPublicKey .getEncoded)
|
|
</span><br/>
|
|
<span class="covered" title="3 out of 3 forms covered">
|
|
057 private (-> kp .getPrivateKey .getPrivateKeyDataPacket .getEncoded)]
|
|
</span><br/>
|
|
<span class="covered" title="6 out of 6 forms covered">
|
|
058 (println (str "Public key: " public))
|
|
</span><br/>
|
|
<span class="covered" title="6 out of 6 forms covered">
|
|
059 (println (str "Private key: " private))
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
060 )
|
|
</span><br/>
|
|
<span class="blank" title="0 out of 0 forms covered">
|
|
061
|
|
</span><br/>
|
|
</body>
|
|
</html>
|