<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/">
    <channel>
        <title>NotionNext BLOG</title>
        <link>https://blog.ioser.store/</link>
        <description>这是一个由NotionNext生成的站点</description>
        <lastBuildDate>Wed, 31 May 2023 01:56:43 GMT</lastBuildDate>
        <docs>https://validator.w3.org/feed/docs/rss2.html</docs>
        <generator>https://github.com/jpmonette/feed</generator>
        <language>zh-CN</language>
        <copyright>All rights reserved 2023, 泥巴电报</copyright>
        <item>
            <title><![CDATA[OpenSSL WatchOS Crash on dyld?]]></title>
            <link>https://blog.ioser.store/article/openssl-crash</link>
            <guid>https://blog.ioser.store/article/openssl-crash</guid>
            <pubDate>Tue, 23 May 2023 00:00:00 GMT</pubDate>
            <description><![CDATA[approach openssl for apple watchos crash]]></description>
            <content:encoded><![CDATA[<div id="container" class="mx-auto undefined"><main class="notion light-mode notion-page notion-block-a2fa88a049b542ad94b7b653b2c7133d"><div class="notion-viewport"></div><div class="notion-collection-page-properties"></div><blockquote class="notion-quote notion-block-729352f2dbc04d67ac857e94555f92b8"><div>I was developing an Apple Watch app that uses AES encryption algorithm in OpenSSL. However, the official OpenSSL repository <!-- -->does not provide frameworks for iOS/WatchOS platforms. Therefore, we need to build it ourselves. Fortunately, there is a reliable OpenSSL framework repository  <!-- --> available for Apple-related systems. We can simply download the repository and use the script in the repository to build an xcframework.</div></blockquote><div class="notion-blank notion-block-7492a34214bf4fdda5d4587fa22a0755"> </div><div class="notion-text notion-block-773998b3500c44ab9b7e5b298d7185fa">Assuming that you have embedded the OpenSSL framework in your project, two problems may occur when building your project for watchOS:</div><h3 class="notion-h notion-h2 notion-h-indent-0 notion-block-879b2a9a97c649da885a7d264e39d619" data-id="879b2a9a97c649da885a7d264e39d619"><span><div id="879b2a9a97c649da885a7d264e39d619" class="notion-header-anchor"></div><a class="notion-hash-link" href="#879b2a9a97c649da885a7d264e39d619" title="1. Build Error - Undefined symbols for architecture arm64 "><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">1. Build Error - Undefined symbols for architecture arm64 </span></span></h3><div class="notion-text notion-block-0593a64290a34c788641c75810a46f9e">This happens because Xcode 14 adds <code class="notion-inline-code">arm64</code> to the Standard Architectures for watchOS.</div><div class="notion-text notion-block-eaf3de47ba9d4db9b831d5582fc22146">Xcode 13.4.1:</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-16800db40d504396a64d38d0c4fc6913"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2F34b99b13-cf73-48ab-9239-53669dd2252a%2FUntitled.png?table=block&amp;id=16800db4-0d50-4396-a64d-38d0c4fc6913" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-492702d6be9d4add9f67a00ae858bafb">Xcode 14:</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-11dee7b1b21646b28cd7fb50e93ea263"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2Fe86feadf-0f0c-48df-96b1-82ceabc2eda5%2FUntitled.png?table=block&amp;id=11dee7b1-b216-46b2-8cd7-fb50e93ea263" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-blank notion-block-b596147184b84eaab75c0230eba60988"> </div><div class="notion-text notion-block-f51023c29f594368a2d9b57a2ca11c7b">Manually settings the Architectures to <code class="notion-inline-code">arm64_32</code> and <code class="notion-inline-code">armv7k</code> instead of using the Standard Archs seems to work for now, but it unknown it will cause problems when watchOS 10.0 will be released, alongside a Watch Series 9 that might not support <code class="notion-inline-code">arm64_32</code> anymore?</div><div class="notion-blank notion-block-fd17d74a60044946836514c9acfef802"> </div><div class="notion-text notion-block-f3addc6a3e7a43bc8c567aec2dfd7ac2">For now you can add <code class="notion-inline-code">arm64</code> to <code class="notion-inline-code">Excluded Architecture</code> to avoid the issue. As far as I know, the latest version of Apple Watch (which is Series 8 at present) is not arm64 architecture yet, so you may need to keep an eye out for any updates on this.</div><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-91af3cbca762444dac8ec6d78f48e6f5" data-id="91af3cbca762444dac8ec6d78f48e6f5"><span><div id="91af3cbca762444dac8ec6d78f48e6f5" class="notion-header-anchor"></div><a class="notion-hash-link" href="#91af3cbca762444dac8ec6d78f48e6f5" title="Reference"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">Reference</span></span></h4><div class="notion-text notion-block-415c9e864569493da35c00587a51f272"><a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://youtrack.jetbrains.com/issue/KT-53107/Add-arm64-support-for-watchOS-targets-Xcode-14">https://youtrack.jetbrains.com/issue/KT-53107/Add-arm64-support-for-watchOS-targets-Xcode-14</a></div><div class="notion-blank notion-block-35dbb0004a2d4ee4b0263e60d80b749f"> </div><h3 class="notion-h notion-h2 notion-h-indent-0 notion-block-37e24d7b43ce413eb2b3ca513f132d40" data-id="37e24d7b43ce413eb2b3ca513f132d40"><span><div id="37e24d7b43ce413eb2b3ca513f132d40" class="notion-header-anchor"></div><a class="notion-hash-link" href="#37e24d7b43ce413eb2b3ca513f132d40" title="2. Crashed on dyld load OpenSSL"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">2. Crashed on dyld load OpenSSL</span></span></h3><div class="notion-text notion-block-49ef71510df1401ba1f741ca1ab8d71e">The watch app crashed upon launching.</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-a8fb2022cbe6442bb7b6774683cb53b7"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2Fa35cd6e3-5123-48c8-8d75-c482da35d560%2FUntitled.png?table=block&amp;id=a8fb2022-cbe6-442b-b7b6-774683cb53b7" alt="Crash Stack" loading="lazy" decoding="async"/><figcaption class="notion-asset-caption">Crash Stack</figcaption></div></figure><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-cea30fd59b844afe869e71bbf0ea88ef"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2Fd660e0ca-6024-4927-8908-c92d70699219%2FUntitled.png?table=block&amp;id=cea30fd5-9b84-4afe-869e-71bbf0ea88ef" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-d6f1dc65b1054ad0be65c9cba16a20fc">Since the crash occurred with a stack on OpenSSL dyld loading, it&#x27;s highly likely that there is an issue within the OpenSSL framework.</div><div class="notion-text notion-block-3cee9870766843049d4ffa179e900d3c">I found a similar issue on Github:</div><div class="notion-text notion-block-93c56484bab843d3aa93883a192deaa1"><a target="_blank" rel="noopener noreferrer" href="https://github.com/openssl/openssl/issues/20155" class="notion-external notion-external-mention"><div class="notion-external-image"><svg viewBox="0 0 260 260"><g><path d="M128.00106,0 C57.3172926,0 0,57.3066942 0,128.00106 C0,184.555281 36.6761997,232.535542 87.534937,249.460899 C93.9320223,250.645779 96.280588,246.684165 96.280588,243.303333 C96.280588,240.251045 96.1618878,230.167899 96.106777,219.472176 C60.4967585,227.215235 52.9826207,204.369712 52.9826207,204.369712 C47.1599584,189.574598 38.770408,185.640538 38.770408,185.640538 C27.1568785,177.696113 39.6458206,177.859325 39.6458206,177.859325 C52.4993419,178.762293 59.267365,191.04987 59.267365,191.04987 C70.6837675,210.618423 89.2115753,204.961093 96.5158685,201.690482 C97.6647155,193.417512 100.981959,187.77078 104.642583,184.574357 C76.211799,181.33766 46.324819,170.362144 46.324819,121.315702 C46.324819,107.340889 51.3250588,95.9223682 59.5132437,86.9583937 C58.1842268,83.7344152 53.8029229,70.715562 60.7532354,53.0843636 C60.7532354,53.0843636 71.5019501,49.6441813 95.9626412,66.2049595 C106.172967,63.368876 117.123047,61.9465949 128.00106,61.8978432 C138.879073,61.9465949 149.837632,63.368876 160.067033,66.2049595 C184.49805,49.6441813 195.231926,53.0843636 195.231926,53.0843636 C202.199197,70.715562 197.815773,83.7344152 196.486756,86.9583937 C204.694018,95.9223682 209.660343,107.340889 209.660343,121.315702 C209.660343,170.478725 179.716133,181.303747 151.213281,184.472614 C155.80443,188.444828 159.895342,196.234518 159.895342,208.176593 C159.895342,225.303317 159.746968,239.087361 159.746968,243.303333 C159.746968,246.709601 162.05102,250.70089 168.53925,249.443941 C219.370432,232.499507 256,184.536204 256,128.00106 C256,57.3066942 198.691187,0 128.00106,0 Z M47.9405593,182.340212 C47.6586465,182.976105 46.6581745,183.166873 45.7467277,182.730227 C44.8183235,182.312656 44.2968914,181.445722 44.5978808,180.80771 C44.8734344,180.152739 45.876026,179.97045 46.8023103,180.409216 C47.7328342,180.826786 48.2627451,181.702199 47.9405593,182.340212 Z M54.2367892,187.958254 C53.6263318,188.524199 52.4329723,188.261363 51.6232682,187.366874 C50.7860088,186.474504 50.6291553,185.281144 51.2480912,184.70672 C51.8776254,184.140775 53.0349512,184.405731 53.8743302,185.298101 C54.7115892,186.201069 54.8748019,187.38595 54.2367892,187.958254 Z M58.5562413,195.146347 C57.7719732,195.691096 56.4895886,195.180261 55.6968417,194.042013 C54.9125733,192.903764 54.9125733,191.538713 55.713799,190.991845 C56.5086651,190.444977 57.7719732,190.936735 58.5753181,192.066505 C59.3574669,193.22383 59.3574669,194.58888 58.5562413,195.146347 Z M65.8613592,203.471174 C65.1597571,204.244846 63.6654083,204.03712 62.5716717,202.981538 C61.4524999,201.94927 61.1409122,200.484596 61.8446341,199.710926 C62.5547146,198.935137 64.0575422,199.15346 65.1597571,200.200564 C66.2704506,201.230712 66.6095936,202.705984 65.8613592,203.471174 Z M75.3025151,206.281542 C74.9930474,207.284134 73.553809,207.739857 72.1039724,207.313809 C70.6562556,206.875043 69.7087748,205.700761 70.0012857,204.687571 C70.302275,203.678621 71.7478721,203.20382 73.2083069,203.659543 C74.6539041,204.09619 75.6035048,205.261994 75.3025151,206.281542 Z M86.046947,207.473627 C86.0829806,208.529209 84.8535871,209.404622 83.3316829,209.4237 C81.8013,209.457614 80.563428,208.603398 80.5464708,207.564772 C80.5464708,206.498591 81.7483088,205.631657 83.2786917,205.606221 C84.8005962,205.576546 86.046947,206.424403 86.046947,207.473627 Z M96.6021471,207.069023 C96.7844366,208.099171 95.7267341,209.156872 94.215428,209.438785 C92.7295577,209.710099 91.3539086,209.074206 91.1652603,208.052538 C90.9808515,206.996955 92.0576306,205.939253 93.5413813,205.66582 C95.054807,205.402984 96.4092596,206.021919 96.6021471,207.069023 Z" fill="#161614"></path></g></svg></div><div class="notion-external-description"><div class="notion-external-title">iOS app is crashing on app launch with openssl 3.07 code with #20137 code PR</div><div class="notion-external-subtitle"><span>Updated <!-- -->Apr 14, 2023</span></div></div></a></div><div class="notion-text notion-block-513eaa6ced0d492e898db7990f484ab9">A openssl repository member mentioned <em><span class="notion-inline-underscore">Is getauxval function available on iOS?</span></em></div><details class="notion-toggle notion-block-58aba288546a4c7da8121e2715a360b4"><summary>Here is the <b>original text</b></summary><div><div class="notion-text notion-block-467c649abf7047f79d9129f5051b8ec0">Is <code class="notion-inline-code">getauxval</code> function available on iOS? Unfortunately openssl uses probing if <code class="notion-inline-code">getauxval</code> is not implemented. Probing works by setting SIGILL handler and trying the instruction whether it triggers SIGILL. If that isn&#x27;t possible to do on iOS, then someone more knowledgeable with iOS and possible devices could suggest some other way how to probe.</div></div></details><div class="notion-text notion-block-6c3eed05ce6c4e77a051a12176817563">And the member suggest the issue author, build with <code class="notion-inline-code">no-asm</code> ,however that will make the crypto algorithms quite slower.</div><div class="notion-blank notion-block-6b7d3fe278b3434983bad0f2f69891f6"> </div><div class="notion-text notion-block-3ee0dd2bca5943d58af66480c06e97e6">To be honest, I really don’t care about the performance between the two algorithms when my app can not launch. I tried the suggestion immediately，here are the workable steps:</div><ol start="1" class="notion-list notion-list-numbered notion-block-4db117213e8e4c25b52d2d4f08a30e63"><li>download <!-- --> repository</li></ol><ol start="2" class="notion-list notion-list-numbered notion-block-933edff991834d2a8cd3ed49ded2f48e"><li>modify the file <code class="notion-inline-code">config/20-ios-tvos-cross.conf</code> </li></ol><pre class="notion-code"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-swift">// change the asm parameter from &quot;armv4_asm&quot; to &quot;no-sam&quot;
&quot;watchos-cross-armv7k&quot; =&gt; {
        inherit_from     =&gt; [ &quot;darwin-common&quot;, &quot;watchos-cross-base&quot;, asm(&quot;no-asm&quot;) ],
        cflags           =&gt; add(&quot;-arch armv7k&quot;),
        perlasm_scheme   =&gt; &quot;ios32&quot;,
        sys_id           =&gt; &quot;watchOS&quot;,
    },
// change the asm parameter from &quot;aarch64_asm&quot; to &quot;no-sam&quot;
    &quot;watchos-cross-arm64_32&quot; =&gt; {
        inherit_from     =&gt; [ &quot;darwin-common&quot;, &quot;watchos-cross-base&quot;, asm(&quot;no-asm&quot;) ],
        cflags           =&gt; add(&quot;-arch arm64_32&quot;),
        perlasm_scheme   =&gt; &quot;ios64&quot;,
        sys_id           =&gt; &quot;watchOS&quot;,
    }</code></pre><ol start="1" class="notion-list notion-list-numbered notion-block-b0d9dfad5dd64f4cacecd5c1b1e0133e"><li>execute the script <code class="notion-inline-code">./</code><code class="notion-inline-code"><a target="_blank" rel="noopener noreferrer" class="notion-link" href="http://build-libssl.sh/">build-libssl.sh</a></code></li></ol><ol start="2" class="notion-list notion-list-numbered notion-block-578a2edc45ce4a59b5ce28772582609d"><li>execute the script <code class="notion-inline-code">./</code><code class="notion-inline-code"><a target="_blank" rel="noopener noreferrer" class="notion-link" href="http://create-xcframework.sh/">create-xcframework.sh</a></code></li></ol><div class="notion-text notion-block-2d07a368c0ae4952b26a775e996e8bb2">Congratulation! You got the workable OpenSSL framework for WatchOS!</div><div class="notion-blank notion-block-156ba4af5cc24956b6026ca6e4f0072e"> </div></main></div>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[如何选择开源协议]]></title>
            <link>https://blog.ioser.store/article/opens-source-protocol</link>
            <guid>https://blog.ioser.store/article/opens-source-protocol</guid>
            <pubDate>Wed, 28 Apr 2021 00:00:00 GMT</pubDate>
            <description><![CDATA[为自己的开源软件选择合适的开源协议]]></description>
            <content:encoded><![CDATA[<div id="container" class="mx-auto undefined"><main class="notion light-mode notion-page notion-block-80e4b7736d5b4b3db0f9e1072c524ab6"><div class="notion-viewport"></div><div class="notion-collection-page-properties"></div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-9dacd5fe4bde4914b5f15b2e6ce5b555" data-id="9dacd5fe4bde4914b5f15b2e6ce5b555"><span><div id="9dacd5fe4bde4914b5f15b2e6ce5b555" class="notion-header-anchor"></div><a class="notion-hash-link" href="#9dacd5fe4bde4914b5f15b2e6ce5b555" title="如何选择开源协议"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">如何选择开源协议</span></span></h2><blockquote class="notion-quote notion-block-65eb485e45d0476ba836d05a6cba1e6d"><div>声明：此文章内容来源于阮一峰的网络日志-如何选择开源许可证？</div></blockquote><div class="notion-text notion-block-07e8c69c266448ed816ad1d5b7fb442c">如何为代码选择开源许可证，这是一个问题。</div><div class="notion-text notion-block-8b2d38b996574f878ec22f8b3d17e395">世界上的开源许可证，大概有<a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://www.gnu.org/licenses/license-list.html">上百种</a>。很少有人搞得清楚它们的区别。即使在最流行的六种----<a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://www.gnu.org/licenses/gpl.html">GPL</a>、<a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://en.wikipedia.org/wiki/BSD_licenses">BSD</a>、<a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://en.wikipedia.org/wiki/MIT_License">MIT</a>、<a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://www.mozilla.org/MPL/">Mozilla</a>、<a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://www.apache.org/licenses/LICENSE-2.0">Apache</a>和<a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://www.gnu.org/copyleft/lesser.html">LGPL</a>----之中做选择，也很复杂。</div><div class="notion-blank notion-block-8aba59235f3c44adb9f46051b58ebb91"> </div><div class="notion-text notion-block-830c809cd97642a9a22392c5b6eba999">乌克兰程序员Paul Bagwell，画了一张分析图，说明应该怎么选择。这是我见过的最简单的讲解，只用两分钟，你就能搞清楚这六种许可证之间的最大区别。</div><div class="notion-text notion-block-d9b0fbf2885b4b16af4a52423c22c60b">这个事吧，一张图片就可以搞定：</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-0765fa1023f9490b8c484d00710b5b64"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2F94f28b39-fceb-4443-8ee0-069b4cf67653%2FUntitled.png?table=block&amp;id=0765fa10-23f9-490b-8c48-4d00710b5b64" alt="notion image" loading="lazy" decoding="async"/></div></figure></main></div>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Clang 插件计算圈复杂度]]></title>
            <link>https://blog.ioser.store/article/clang-complex</link>
            <guid>https://blog.ioser.store/article/clang-complex</guid>
            <pubDate>Tue, 17 Mar 2020 00:00:00 GMT</pubDate>
            <content:encoded><![CDATA[<div id="container" class="mx-auto undefined"><main class="notion light-mode notion-page notion-block-b8d4d06facf4418baea48a59880f0613"><div class="notion-viewport"></div><div class="notion-collection-page-properties"></div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-f608248955064a388bdcc1d6d7190a15"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2F78597d76-9e2d-493c-8ef1-3b9b1bc6d7a6%2FUntitled.png?table=block&amp;id=f6082489-5506-4a38-8bdc-c1d6d7190a15" alt="notion image" loading="lazy" decoding="async"/></div></figure><h3 class="notion-h notion-h2 notion-h-indent-0 notion-block-2bc95fa2fc3c423696c5ec11865c3da0" data-id="2bc95fa2fc3c423696c5ec11865c3da0"><span><div id="2bc95fa2fc3c423696c5ec11865c3da0" class="notion-header-anchor"></div><a class="notion-hash-link" href="#2bc95fa2fc3c423696c5ec11865c3da0" title="圈复杂度"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><b>圈复杂度</b></span></span></h3><blockquote class="notion-quote notion-block-c93cf95e2578437f873fbb5b713ca9db"><div>圈复杂度（Cyclomatic complexity，简写CC）也称为条件复杂度，是一种代码复杂度的衡量标准。由托马斯·J·麦凯布（Thomas J. McCabe, Sr.）于1976年提出，用来表示程序的复杂度，其符号为VG或是M。它可以用来衡量一个模块判定结构的复杂程度，数量上表现为独立现行路径条数，也可理解为覆盖所有的可能情况最少使用的测试用例数。圈复杂度大说明程序代码的判断逻辑复杂，可能质量低且难于测试和 维护。程序的可能错误和高的圈复杂度有着很大关系。</div><div class="notion-text notion-block-bfb73ec6cb6a448180b8e1967ebb53fc">通俗得讲圈复杂度就是确定某一方法到达100%的覆盖率将需要多少条测试用例</div></blockquote><div class="notion-text notion-block-f426a757f9cf454c8a10059fb6677c8b">References:</div><ul class="notion-list notion-list-disc notion-block-4c0b290c50ea4db48d585dea6384d1ce"><li>McCabe (December 1976). “A Complexity Measure”.<!-- -->IEEE Transactions on Software Engineering: 308–320<a target="_blank" rel="noopener noreferrer" class="notion-link" href="http://www.literateprogramming.com/mccabe.pdf">http://www.literateprogramming.com/mccabe.pdf</a></li></ul><h3 class="notion-h notion-h2 notion-h-indent-0 notion-block-077b755adbd8400e8b113b917d829614" data-id="077b755adbd8400e8b113b917d829614"><span><div id="077b755adbd8400e8b113b917d829614" class="notion-header-anchor"></div><a class="notion-hash-link" href="#077b755adbd8400e8b113b917d829614" title="圈复杂度算法"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><b>圈复杂度算法</b></span></span></h3><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-b924d64f072f4d42a6c8393edb8bc182" data-id="b924d64f072f4d42a6c8393edb8bc182"><span><div id="b924d64f072f4d42a6c8393edb8bc182" class="notion-header-anchor"></div><a class="notion-hash-link" href="#b924d64f072f4d42a6c8393edb8bc182" title="点边计算法"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><b>点边计算法</b></span></span></h4><div class="notion-text notion-block-7418edd9ed4d4128aa32a78fb701044e">计算公式</div><pre class="notion-code"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-plain text">V(G) = e – n + 2 * p</code></pre><blockquote class="notion-quote notion-block-ab2a05d4995445339471bc7c0290b263"><div>e：控制流图中边的数量（对应代码中顺序结构的部分）</div><div class="notion-text notion-block-2d28d57dae3642328fa9a3a0cb0527ad">n：代表在控制流图中的判定节点数量，包括起点和终点（对应代码中的分支语句）</div><div class="notion-text notion-block-ef370be777594153a2accfab61b986ef">ps：所有终点只计算一次，即使有多个 return 或者 throw</div></blockquote><blockquote class="notion-quote notion-block-742305adc4b242169c63947b407db258"><div>p：独立组件的个数</div></blockquote><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-34a95059c13044568dca09d559a61d67" data-id="34a95059c13044568dca09d559a61d67"><span><div id="34a95059c13044568dca09d559a61d67" class="notion-header-anchor"></div><a class="notion-hash-link" href="#34a95059c13044568dca09d559a61d67" title="节点计算法"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><b>节点计算法</b></span></span></h4><div class="notion-text notion-block-a84caf6beab743a68177eb8620423271">圈复杂度实际上就是等于判定节点的数量再加上1，也即控制流图的区域数，对应的计算公式为：</div><pre class="notion-code"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-plain text">V (G) = P + 1
</code></pre><div class="notion-text notion-block-f476386dce054c4ab8ed9fcb1c3e4593">其中P为判定节点数，判定节点举例：</div><ul class="notion-list notion-list-disc notion-block-4e5dc3486dae4ce3b02d278e90623d98"><li>if语句</li></ul><ul class="notion-list notion-list-disc notion-block-428090fee7fa41718076c51227b5aef6"><li>while语句</li></ul><ul class="notion-list notion-list-disc notion-block-8c59b47983874bdc828668ee4edc6443"><li>for语句</li></ul><ul class="notion-list notion-list-disc notion-block-bfa143ff2de9473fb7ad01ccb883dac0"><li>case语句</li></ul><ul class="notion-list notion-list-disc notion-block-e1d0b1e6a33c4e33b4127157fa955ab7"><li>catch语句</li></ul><ul class="notion-list notion-list-disc notion-block-80ed3f955c9b47ea99966f26bc302efb"><li>and和or布尔操作</li></ul><ul class="notion-list notion-list-disc notion-block-a21f286bd816447baf8534cb7d2cf44b"><li>?:三元运算符</li></ul><div class="notion-text notion-block-3960b4fd7f594af2b7534ace6652560a">常见语句的控制流：</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-9c8e9e967ea74866bad8b35d3b131d8b"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:633px;max-width:100%;flex-direction:column"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2F2626fd6f-003d-4c85-9b92-5a3f904edf73%2FUntitled.png?table=block&amp;id=9c8e9e96-7ea7-4866-bad8-b35d3b131d8b" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-d17ecf03e783472a8dc6cd104c9e9529">1、所有终点只计算一次，即便有多个return或者throw；</div><div class="notion-text notion-block-01af41e6de3041bb82ef991a54cb7920">2、节点对应代码中的分支语句</div><div class="notion-text notion-block-a96b5528839b4259b5902b3583b58de6">使用Clang插件代码实现自动检测的话，我们使用节点计算法</div><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-7f8e4c04d4f44f4e8b144c27615273a2" data-id="7f8e4c04d4f44f4e8b144c27615273a2"><span><div id="7f8e4c04d4f44f4e8b144c27615273a2" class="notion-header-anchor"></div><a class="notion-hash-link" href="#7f8e4c04d4f44f4e8b144c27615273a2" title="小结"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><b>小结</b></span></span></h4><div class="notion-text notion-block-41a0aa89c4204864890458d5e29e15f9">如<a target="_blank" rel="noopener noreferrer" class="notion-link" href="http://kaelzhang81.github.io/2017/06/18/%E8%AF%A6%E8%A7%A3%E5%9C%88%E5%A4%8D%E6%9D%82%E5%BA%A6/#%E6%80%9D%E8%BE%A81-%E9%AB%98%E5%A4%8D%E6%9D%82%E5%BA%A6%E7%9A%84%E4%BB%A3%E7%A0%81%E6%98%AF%E5%90%A6%E5%8F%AF%E7%BB%B4%E6%8A%A4%E6%80%A7%E5%B7%AE">高复杂度的代码是否可维护性差</a> 圈复杂度高的情况也并不是需要重构</div><div class="notion-text notion-block-6b44ba1dca614bc69304b05cfc6a3677">如<a target="_blank" rel="noopener noreferrer" class="notion-link" href="http://kaelzhang81.github.io/2017/06/18/%E8%AF%A6%E8%A7%A3%E5%9C%88%E5%A4%8D%E6%9D%82%E5%BA%A6/#%E6%80%9D%E8%BE%A82-%E5%A4%8D%E6%9D%82%E5%BA%A6%E7%9B%B8%E5%90%8C%E7%9A%84%E4%BB%A3%E7%A0%81%E6%98%AF%E5%90%A6%E6%98%AF%E4%B8%80%E8%87%B4%E7%9A%84">复杂度相同的代码是否是一致的</a> 圈复杂度相同的情况代码健康状况也不同</div><div class="notion-text notion-block-93a12914668b45338f125bdb67a3115d">圈复杂度还需要具体情况具体分析，其只能作为重构的一个度量指标，作为决策的一个参考依据。</div><div class="notion-text notion-block-3bc9b5d929604faf93d3355da68becea">降低圈复杂度不在本文讨论范围，可以点击 <a target="_blank" rel="noopener noreferrer" class="notion-link" href="http://kaelzhang81.github.io/2017/06/18/%E8%AF%A6%E8%A7%A3%E5%9C%88%E5%A4%8D%E6%9D%82%E5%BA%A6/#%E9%99%8D%E4%BD%8E%E5%9C%88%E5%A4%8D%E6%9D%82%E5%BA%A6%E7%9A%84%E6%96%B9%E6%B3%95">降低圈复杂度方法</a> 链接查看</div><h3 class="notion-h notion-h2 notion-h-indent-0 notion-block-9d335901ce47471da4f2fcc16e659518" data-id="9d335901ce47471da4f2fcc16e659518"><span><div id="9d335901ce47471da4f2fcc16e659518" class="notion-header-anchor"></div><a class="notion-hash-link" href="#9d335901ce47471da4f2fcc16e659518" title="Clang 插件逻辑"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><b>Clang 插件逻辑</b></span></span></h3><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-0a44818d50e546c7b7093f18d743f9cc" data-id="0a44818d50e546c7b7093f18d743f9cc"><span><div id="0a44818d50e546c7b7093f18d743f9cc" class="notion-header-anchor"></div><a class="notion-hash-link" href="#0a44818d50e546c7b7093f18d743f9cc" title="Clang命令集"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><b>Clang命令集</b></span></span></h4><ol start="1" class="notion-list notion-list-numbered notion-block-a2a77df6022c4e7bab10abf053dbd819"><li>clang分析AST</li><ol class="notion-list notion-list-numbered notion-block-a2a77df6022c4e7bab10abf053dbd819"><div class="notion-text notion-block-e13f4fbbc6cf4126bd854b00f55d2c5b">使用命令：<code class="notion-inline-code">clang -Xclang -ast-dump -fsyntax-only xxx.m</code> ，即可分析xxx.m 的 AST</div><pre class="notion-code"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-plain text">clang -Xclang -ast-dump -fsyntax-only jake.m
</code></pre></ol></ol><ol start="2" class="notion-list notion-list-numbered notion-block-72c44423c278429e9211ab09171bc0c4"><li>clang-query作为clang的一个工具，可交互式检验Matcher正确性和有效性，可探索AST的结构和关系。</li><ol class="notion-list notion-list-numbered notion-block-72c44423c278429e9211ab09171bc0c4"><pre class="notion-code"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-plain text">~/clang-llvm/build/bin/clang-query jake.m
</code></pre></ol></ol><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-418c8ea313784f65a419eadcb47fc6e1" data-id="418c8ea313784f65a419eadcb47fc6e1"><span><div id="418c8ea313784f65a419eadcb47fc6e1" class="notion-header-anchor"></div><a class="notion-hash-link" href="#418c8ea313784f65a419eadcb47fc6e1" title="Clang 圈复杂度算法实现"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><b>Clang 圈复杂度算法实现</b></span></span></h4><div class="notion-text notion-block-4a5d0020e4584e22adaa6980b0ec78d7">文中的两种圈复杂度计算方法，点边计算对人更加直观，不过在代码中实现，用节点计算法对计算机而言才是更直观的方法。</div><pre class="notion-code"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-plain text"> V (G) = P + 1
</code></pre><div class="notion-text notion-block-ad1137f5cfcb465d9f6b4a02ef64067e">只需要统计一个模块（函数）中所有P出现的次数，具体在Clang中可以重载<code class="notion-inline-code">RecursiveASTVisitor</code> 类（此类用于搜索整个AST，并访问每一个节点），然后重载里面的这些方法</div><pre class="notion-code"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-c">bool VisitIfStmt(clang::IfStmt *stmt);
bool VisitForStmt(clang::ForStmt *stmt);
bool VisitObjCForCollectionStmt(clang::ObjCForCollectionStmt *stmt);
bool VisitWhileStmt(clang::WhileStmt *stmt);
bool VisitDoStmt(clang::DoStmt *stmt);
bool VisitCaseStmt(clang::CaseStmt *stmt);
bool VisitObjCAtCatchStmt(clang::ObjCAtCatchStmt *stmt);
bool VisitCXXCatchStmt(clang::CXXCatchStmt *stmt);
bool VisitConditionalOperator(clang::ConditionalOperator *op);
bool VisitBinaryOperator(clang::BinaryOperator *op);
</code></pre><div class="notion-text notion-block-1321648274be4911b66bf44a3c79486d">在重载的方法内对此模块中节点P的次数进行一次累加并返回true，如:</div><pre class="notion-code"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-c">bool VisitIfStmt(clang::IfStmt *stmt) {
    _count++;
    return true;
}
</code></pre><div class="notion-text notion-block-a1a20a2a8ed34e7fb7affab77e94bc36">遍历一次模块语法树之后获得此模块的圈复杂度值，再在另一个<code class="notion-inline-code">RecursiveASTVisitor</code>类中进行判断，一般圈复杂度不要超过10，以下规范来自网络仅做参考</div><table class="notion-simple-table notion-block-babb828467c44f4a8928a51337680194"><tbody><tr class="notion-simple-table-row notion-block-710a027facc2424598bcfa4a0467b696"><td class="" style="width:120px"><div class="notion-simple-table-cell"><b>圈复杂度</b></div></td><td class="" style="width:120px"><div class="notion-simple-table-cell"><b>代码状况</b></div></td><td class="" style="width:120px"><div class="notion-simple-table-cell"><b>可测性</b></div></td><td class="" style="width:120px"><div class="notion-simple-table-cell"><b>维护成本</b></div></td></tr><tr class="notion-simple-table-row notion-block-2dc348b2552f4911a17b7c80cff6cdcd"><td class="" style="width:120px"><div class="notion-simple-table-cell">1-10</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">清晰、结构化</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">高</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">低</div></td></tr><tr class="notion-simple-table-row notion-block-c6bcaf8187b44432829037853da3d82f"><td class="" style="width:120px"><div class="notion-simple-table-cell">10-20</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">复杂</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">中</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">中</div></td></tr><tr class="notion-simple-table-row notion-block-ad0514855132488daa0828bc15f04cc4"><td class="" style="width:120px"><div class="notion-simple-table-cell">20-30</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">非常复杂</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">低</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">高</div></td></tr><tr class="notion-simple-table-row notion-block-ed168a329b4a414e8308f3f2eaf8e52e"><td class="" style="width:120px"><div class="notion-simple-table-cell">30</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">不可读</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">不可测</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">非常高</div></td></tr></tbody></table><div class="notion-text notion-block-8df6d62550ba44739f973fccd5ebf02e">在模块编译完成后，将会在模块的结尾进行提示，类似形式如下：</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-28c14f1a61e140c0bfb70d0e710368c9"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2F720c82f0-ad8a-4b24-9d32-06d9f9a0ebfa%2FUntitled.png?table=block&amp;id=28c14f1a-61e1-40c0-bfb7-0d0e710368c9" alt="notion image" loading="lazy" decoding="async"/></div></figure><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-3dd2d56c7b8f41e5a3777e837815fc24" data-id="3dd2d56c7b8f41e5a3777e837815fc24"><span><div id="3dd2d56c7b8f41e5a3777e837815fc24" class="notion-header-anchor"></div><a class="notion-hash-link" href="#3dd2d56c7b8f41e5a3777e837815fc24" title="思考"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><b>思考</b></span></span></h4><div class="notion-text notion-block-359533f79e3a40b6bea8f2db5ec14ee7">如下是一个圈复杂度大于10的AST语法树示例：</div><pre class="notion-code"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-plain text">CompoundStmt 0x7ff7f2898788
|-CallExpr 0x7ff7f289af60 &#x27;void&#x27;
| |-ImplicitCastExpr 0x7ff7f289af48 &#x27;void (*)(id, ...)&#x27; &lt;FunctionToPointerDecay&gt;
| | `-DeclRefExpr 0x7ff7f289ae60 &#x27;void (id, ...)&#x27; Function 0x7ff7f2055540 &#x27;NSLog&#x27; &#x27;void (id, ...)&#x27;
| `-ImplicitCastExpr 0x7ff7f289af88 &#x27;id&#x27;:&#x27;id&#x27; &lt;BitCast&gt;
|   `-ObjCStringLiteral 0x7ff7f289aed0 &#x27;NSString *&#x27;
|     `-StringLiteral 0x7ff7f289aeb8 &#x27;char [1]&#x27; lvalue &quot;&quot;
|-DeclStmt 0x7ff7f289b040
| `-VarDecl 0x7ff7f289afb8  used num &#x27;int&#x27; cinit
|   `-IntegerLiteral 0x7ff7f289b020 &#x27;int&#x27; 0
|-IfStmt 0x7ff7f289b238 has_else
| |-BinaryOperator 0x7ff7f289b0c8 &#x27;int&#x27; &#x27;==&#x27;
| | |-ImplicitCastExpr 0x7ff7f289b0b0 &#x27;int&#x27; &lt;LValueToRValue&gt;
| | | `-DeclRefExpr 0x7ff7f289b058 &#x27;int&#x27; lvalue Var 0x7ff7f289afb8 &#x27;num&#x27; &#x27;int&#x27;
| | `-IntegerLiteral 0x7ff7f289b090 &#x27;int&#x27; 0
| |-CompoundStmt 0x7ff7f289b1d8
| | `-IfStmt 0x7ff7f289b1c0
| |   |-BinaryOperator 0x7ff7f289b158 &#x27;int&#x27; &#x27;==&#x27;
| |   | |-ImplicitCastExpr 0x7ff7f289b140 &#x27;int&#x27; &lt;LValueToRValue&gt;
| |   | | `-DeclRefExpr 0x7ff7f289b0e8 &#x27;int&#x27; lvalue Var 0x7ff7f289afb8 &#x27;num&#x27; &#x27;int&#x27;
| |   | `-UnaryOperator 0x7ff7f289b128 &#x27;int&#x27; prefix &#x27;-&#x27;
| |   |   `-IntegerLiteral 0x7ff7f289b108 &#x27;int&#x27; 1
| |   `-CompoundStmt 0x7ff7f289b1a8
| |     `-ReturnStmt 0x7ff7f289b198
| |       `-IntegerLiteral 0x7ff7f289b178 &#x27;int&#x27; 0
| `-CompoundStmt 0x7ff7f289b220
|   `-ReturnStmt 0x7ff7f289b210
|     `-IntegerLiteral 0x7ff7f289b1f0 &#x27;int&#x27; 0
|-DeclStmt 0x7ff7f289b300
| `-VarDecl 0x7ff7f289b278  used index &#x27;int&#x27; cinit
|   `-IntegerLiteral 0x7ff7f289b2e0 &#x27;int&#x27; 0
|-SwitchStmt 0x7ff7f289b368
| |-ImplicitCastExpr 0x7ff7f289b350 &#x27;int&#x27; &lt;LValueToRValue&gt;
| | `-DeclRefExpr 0x7ff7f289b318 &#x27;int&#x27; lvalue Var 0x7ff7f289b278 &#x27;index&#x27; &#x27;int&#x27;
| `-CompoundStmt 0x7ff7f2898700
|   |-CaseStmt 0x7ff7f289b3c0
|   | |-ConstantExpr 0x7ff7f289b3a8 &#x27;int&#x27;
|   | | `-IntegerLiteral 0x7ff7f289b388 &#x27;int&#x27; 1
|   | `-BreakStmt 0x7ff7f289b3e8
|   |-CaseStmt 0x7ff7f2898438
|   | |-ConstantExpr 0x7ff7f2898420 &#x27;int&#x27;
|   | | `-IntegerLiteral 0x7ff7f2898400 &#x27;int&#x27; 2
|   | `-BreakStmt 0x7ff7f2898460
|   |-CaseStmt 0x7ff7f28984a0
|   | |-ConstantExpr 0x7ff7f2898488 &#x27;int&#x27;
|   | | `-IntegerLiteral 0x7ff7f2898468 &#x27;int&#x27; 3
|   | `-BreakStmt 0x7ff7f28984c8
|   |-CaseStmt 0x7ff7f2898508
|   | |-ConstantExpr 0x7ff7f28984f0 &#x27;int&#x27;
|   | | `-IntegerLiteral 0x7ff7f28984d0 &#x27;int&#x27; 4
|   | `-BreakStmt 0x7ff7f2898530
|   |-CaseStmt 0x7ff7f2898570
|   | |-ConstantExpr 0x7ff7f2898558 &#x27;int&#x27;
|   | | `-IntegerLiteral 0x7ff7f2898538 &#x27;int&#x27; 5
|   | `-BreakStmt 0x7ff7f2898598
|   |-CaseStmt 0x7ff7f28985d8
|   | |-ConstantExpr 0x7ff7f28985c0 &#x27;int&#x27;
|   | | `-IntegerLiteral 0x7ff7f28985a0 &#x27;int&#x27; 6
|   | `-BreakStmt 0x7ff7f2898600
|   |-CaseStmt 0x7ff7f2898640
|   | |-ConstantExpr 0x7ff7f2898628 &#x27;int&#x27;
|   | | `-IntegerLiteral 0x7ff7f2898608 &#x27;int&#x27; 7
|   | `-BreakStmt 0x7ff7f2898668
|   |-CaseStmt 0x7ff7f28986a8
|   | |-ConstantExpr 0x7ff7f2898690 &#x27;int&#x27;
|   | | `-IntegerLiteral 0x7ff7f2898670 &#x27;int&#x27; 8
|   | `-BreakStmt 0x7ff7f28986d0
|   `-DefaultStmt 0x7ff7f28986e0
|     `-BreakStmt 0x7ff7f28986d8
`-ReturnStmt 0x7ff7f2898778
  `-IntegerLiteral 0x7ff7f2898758 &#x27;int&#x27; 0
</code></pre><div class="notion-text notion-block-3d6f941e38e5494bbe295bbf2332d729">其源码为：</div><pre class="notion-code"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-c">- (int)func {
    NSLog(@&quot;&quot;);
    int num = 0;
    if (num == 0) {
        if (num == -1) {
            return 0;
        }
    } else {
        return 0;
    }
    int index = 0;
    switch (index) {
        case 1:

            break;
        case 2:

            break;
        case 3:

            break;
        case 4:

            break;
        case 5:

            break;
        case 6:

            break;
        case 7:

            break;
        case 8:

            break;

        default:
            break;
    }
    return 0;
}
</code></pre><div class="notion-text notion-block-27430dd6dc9e456a9c6586930c0ba276"><a target="_blank" rel="noopener noreferrer" class="notion-link" href="http://kaelzhang81.github.io/2017/06/18/%E8%AF%A6%E8%A7%A3%E5%9C%88%E5%A4%8D%E6%9D%82%E5%BA%A6/#%E6%80%9D%E8%BE%A81-%E9%AB%98%E5%A4%8D%E6%9D%82%E5%BA%A6%E7%9A%84%E4%BB%A3%E7%A0%81%E6%98%AF%E5%90%A6%E5%8F%AF%E7%BB%B4%E6%8A%A4%E6%80%A7%E5%B7%AE">高复杂度的代码是否可维护性差</a></div><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-b6a164cedaa440bf8c29a6cc83fdcf12" data-id="b6a164cedaa440bf8c29a6cc83fdcf12"><span><div id="b6a164cedaa440bf8c29a6cc83fdcf12" class="notion-header-anchor"></div><a class="notion-hash-link" href="#b6a164cedaa440bf8c29a6cc83fdcf12" title="Pod 集成"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><b>Pod 集成</b></span></span></h4><pre class="notion-code"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-ruby">pod &#x27;TYCCDetector&#x27;, &#x27;0.0.1&#x27;, :configuration =&gt; &#x27;Debug&#x27;

post_install do |installer|
        installer.pods_project.targets.each do |target|
              installer.development_pod_targets().each do |dp_target|
                  if target.name == dp_target.name
                       target.build_configurations.each do |config|
                              config.build_settings[&quot;COMPILER_INDEX_STORE_ENABLE&quot;] = &#x27;NO&#x27;
                              config.build_settings[&quot;OTHER_CFLAGS&quot;] = &#x27;-Xclang -load -Xclang $(SRCROOT)/TYCCDetector/TYCCDetector/Clang/lib/CCDetector.dylib -Xclang -add-plugin -Xclang CCDetector&#x27;
                              config.build_settings[&quot;CC&quot;] = &quot;$(SRCROOT)/TYCCDetector/TYCCDetector/Clang/bin/clang&quot;
                              config.build_settings[&quot;CXX&quot;] = &quot;$(SRCROOT)/TYCCDetector/TYCCDetector/Clang/bin/clang++&quot;end
                  end
              end
        end
end

</code></pre><h3 class="notion-h notion-h2 notion-h-indent-0 notion-block-a1b7354b0550420ab40da1a8233bb290" data-id="a1b7354b0550420ab40da1a8233bb290"><span><div id="a1b7354b0550420ab40da1a8233bb290" class="notion-header-anchor"></div><a class="notion-hash-link" href="#a1b7354b0550420ab40da1a8233bb290" title="Reference"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><b>Reference</b></span></span></h3><div class="notion-text notion-block-d7d374ef651443f3a971ae338c41b5bd"><a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://clang.llvm.org/doxygen/classclang_1_1PluginASTAction.html#a738fc8000ed0a254d23fb44f0fd1d54c">Clang 官方文档</a></div><div class="notion-text notion-block-4f95772c5d134c8fa3857f9cefadc33d"><a target="_blank" rel="noopener noreferrer" class="notion-link" href="http://kaelzhang81.github.io/2017/06/18/%E8%AF%A6%E8%A7%A3%E5%9C%88%E5%A4%8D%E6%9D%82%E5%BA%A6/">详解圈复杂度</a></div><div class="notion-text notion-block-47c710ad6e6342a88a60422bb46b1507"><a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://juejin.im/post/59bb8b546fb9a00a4247532e#heading-2">美团-代码质量管控 -- 复杂度检测</a></div><div class="notion-text notion-block-8a24dd7e283d4f02ab07881a321f8b9f"><a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://oclint-docs.readthedocs.io/en/stable/rules/size.html">OCLint Docs</a></div><div class="notion-text notion-block-ee0eff04ce394544899b99f4e736f198"><a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://blog.csdn.net/vincentiss/article/details/54617915">https://blog.csdn.net/vincentiss/article/details/54617915</a></div><div class="notion-text notion-block-cf6b5f4655a1434eb001fa19dd11d26e"><a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://mp.weixin.qq.com/s?__biz=MzUxMzcxMzE5Ng==&amp;mid=2247488360&amp;idx=1&amp;sn=94fba30a87d0f9bc0b9ff94d3fed3386&amp;source=41#wechat_redirect">基于clang插件的一种iOS包大小瘦身方案</a></div><div class="notion-text notion-block-615e29761d4f4894bd9a38b50e081d2e"><a target="_blank" rel="noopener noreferrer" class="notion-link" href="http://clang.llvm.org/docs/ExternalClangExamples.html">LLVM 官方 ExternalClangExamples</a></div><div class="notion-text notion-block-522c0a4ec9cf4f2f97bece1ec39ef9e7"><a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://cloud.tencent.com/developer/article/1523137">ASTMatcher分析函数调用链</a></div></main></div>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[被思绪戳穿的国庆节]]></title>
            <link>https://blog.ioser.store/article/national-thaught</link>
            <guid>https://blog.ioser.store/article/national-thaught</guid>
            <pubDate>Fri, 06 Oct 2017 00:00:00 GMT</pubDate>
            <content:encoded><![CDATA[<div id="container" class="mx-auto undefined"><main class="notion light-mode notion-page notion-block-0787154cbecd4afe9d042501c4022c82"><div class="notion-viewport"></div><div class="notion-collection-page-properties"></div><div class="notion-text notion-block-1d104388d618494a9184a6804df09913">我一直觉得自己是一个对过去记忆很不敏感的人，写这段文字的时候在回想着往年的国庆在哪。粗粗一想有印象地只有大二的时候跟两个同学一起骑车去穷游的经历。</div><div class="notion-text notion-block-91be2e6fdd88409ebe27f5bce5fe961d">我现在不太喜欢旅游，没有向往哪里特别想去某个地方旅游的想法。今年的国庆长假，有几个老友相约出游，却也提不起兴趣，之后相互也没有再响应出游计划也就不了了之，最后相互一句 “下次” 一溜而过。</div><h4 class="notion-h notion-h3 notion-h-indent-0 notion-block-0909330c012f47389e12bbc17eed8d13" data-id="0909330c012f47389e12bbc17eed8d13"><span><div id="0909330c012f47389e12bbc17eed8d13" class="notion-header-anchor"></div><a class="notion-hash-link" href="#0909330c012f47389e12bbc17eed8d13" title="曾"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">曾</span></span></h4><div class="notion-text notion-block-b64cf51ea76a47a8b2f835be2a8bcb93">曾经也是向往过一群朋友出游，还有跟女朋友一起旅游。现在没有了向往，遇到一次出游的机会我甚至会评估好久这样的一段旅行有什么意义。多数都激不起我心中的波澜，因为几次曾经的经历让我的心境不再为它们所颤动。曾经听一个人说理性的自己和感性的自己这样的概念，这两个自己做出来的决定是截然不同的，没有波澜的自己当然都是理性的。冷淡的日子安静的自己，宁愿回家待7天。</div><h4 class="notion-h notion-h3 notion-h-indent-0 notion-block-03dff9dca5c0404ca6c2097f6ff2dd98" data-id="03dff9dca5c0404ca6c2097f6ff2dd98"><span><div id="03dff9dca5c0404ca6c2097f6ff2dd98" class="notion-header-anchor"></div><a class="notion-hash-link" href="#03dff9dca5c0404ca6c2097f6ff2dd98" title="十年"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">十年</span></span></h4><div class="notion-text notion-block-a502e7d6d3d1465f9a52c5fb0e0deb58">十年 这个词，对我来说曾一直是很庞大的量级，这次竟被我爸轻易地用在了我身上。以往听到这个词后面跟的话，都不在我的记忆范围内，但是这回...十年前的那些我都历历在目。只记得几年前，却不曾想已经是十年前。</div><h4 class="notion-h notion-h3 notion-h-indent-0 notion-block-9caf025891eb4a589d35cdec3ac45c78" data-id="9caf025891eb4a589d35cdec3ac45c78"><span><div id="9caf025891eb4a589d35cdec3ac45c78" class="notion-header-anchor"></div><a class="notion-hash-link" href="#9caf025891eb4a589d35cdec3ac45c78" title="变"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">变</span></span></h4><div class="notion-text notion-block-be18d70aac8c4d1999683be7dc389e5d">听说我回家之前几个表妹已经回来过又走了，而且还是抱着自己刚出生的孩子来的。堂弟也带着的他女朋友跟他妈妈正打麻将。我姐姐的双胞胎这个月底也要出生了。我？ 我现在一头黄发，满嘴胡渣。一直默默地耕耘着自己的未来，一回头发现周围的未来已来。当然也有不变得，经过10多年，乡下的样貌倒改变不是很大，还是有儿时的感觉。</div><h4 class="notion-h notion-h3 notion-h-indent-0 notion-block-ed6e8ed86e4c4a1aa70ff42764cf961c" data-id="ed6e8ed86e4c4a1aa70ff42764cf961c"><span><div id="ed6e8ed86e4c4a1aa70ff42764cf961c" class="notion-header-anchor"></div><a class="notion-hash-link" href="#ed6e8ed86e4c4a1aa70ff42764cf961c" title="寂"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">寂</span></span></h4><div class="notion-text notion-block-476053665b784f2d9762a4227a013b04">在家我选择了电脑，历年长此以往。我不知道在成长过程中，电脑是不是对性格的养成有助攻。它给了逃避的港湾？我只是觉得它更有意义。我给人的印象就跟电脑关联在了一起。出去玩，我也可以玩得很好。但往往不想，或许用一个字概括 “宅” ？</div><h4 class="notion-h notion-h3 notion-h-indent-0 notion-block-a928d74ff2e44a2aaf10c7b5ab7f727d" data-id="a928d74ff2e44a2aaf10c7b5ab7f727d"><span><div id="a928d74ff2e44a2aaf10c7b5ab7f727d" class="notion-header-anchor"></div><a class="notion-hash-link" href="#a928d74ff2e44a2aaf10c7b5ab7f727d" title="结"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">结</span></span></h4><div class="notion-text notion-block-7955d74ead6c4c81a2cb2b50aac583fb">看了两天的《权利的游戏》，准备开始代码一波。然后整理思绪，继续耕耘我的世界。</div></main></div>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[关于MacOS Ventura 遇到 Git 仓库无法通过 ssh 拉取问题]]></title>
            <link>https://blog.ioser.store/article/openssh-rsa</link>
            <guid>https://blog.ioser.store/article/openssh-rsa</guid>
            <pubDate>Sat, 27 May 2023 00:00:00 GMT</pubDate>
            <content:encoded><![CDATA[<div id="container" class="mx-auto undefined"><main class="notion light-mode notion-page notion-block-e9e918a8294e497298de934d2004d190"><div class="notion-viewport"></div><div class="notion-collection-page-properties"></div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-6b352c081c5e4f52bed13db0aa1c2f6b" data-id="6b352c081c5e4f52bed13db0aa1c2f6b"><span><div id="6b352c081c5e4f52bed13db0aa1c2f6b" class="notion-header-anchor"></div><a class="notion-hash-link" href="#6b352c081c5e4f52bed13db0aa1c2f6b" title="前置条件"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">前置条件</span></span></h2><ul class="notion-list notion-list-disc notion-block-df20823e902249749ce86ae05cf7021d"><li>正确生成并配置本地 ssh rsa 公私钥</li></ul><ul class="notion-list notion-list-disc notion-block-a63231d9b4b74a8f8039ee38ef4743e5"><li>GitLab 中也已经配置了公钥</li></ul><ul class="notion-list notion-list-disc notion-block-a9ac2c89a1364e98b6897b9ca978511c"><li>账户有权限访问目标仓库</li></ul><ul class="notion-list notion-list-disc notion-block-f2a89efce4d3495ebb74952eea71faa8"><li>MacOS 系统是 Ventura</li></ul><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-8335168c507b4bf7b648ee66045e1282" data-id="8335168c507b4bf7b648ee66045e1282"><span><div id="8335168c507b4bf7b648ee66045e1282" class="notion-header-anchor"></div><a class="notion-hash-link" href="#8335168c507b4bf7b648ee66045e1282" title="问题表现"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">问题表现</span></span></h2><pre class="notion-code"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-plain text">ssh -T git@gitlab.com
git@gitlab.com&#x27;s password:
Permission denied, please try again.
git@gitlab.com&#x27;s password:
Permission denied, please try again.
git@gitlab.com&#x27;s password:
git@gitlab.com: Permission denied (publickey,password).</code></pre><div class="notion-text notion-block-142091be862b4ad39f61e13cfcb84eb5">直接使用 ssh 拉取代码也会遇到相同的问题，需要向我们咨询秘钥。</div><div class="notion-text notion-block-76e82acb732d41a8bb6b241ea05d65d6">直观上看这就非常反认知，使用ssh不是公钥直接添加GitLab就可以通讯了吗，为什么还需要密码？ 而且这是什么密码（尝试了GitLal账户和RSA秘钥密码都不正确）？</div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-f8374aa56ae7469482f59e0df6faa729" data-id="f8374aa56ae7469482f59e0df6faa729"><span><div id="f8374aa56ae7469482f59e0df6faa729" class="notion-header-anchor"></div><a class="notion-hash-link" href="#f8374aa56ae7469482f59e0df6faa729" title="原因分析"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">原因分析</span></span></h2><div class="notion-text notion-block-39582f7a8a314d469fa88ca14197fbc8">通过 <code class="notion-inline-code">ssh -vvv git@gitlab.com</code> 分析连接过程</div><pre class="notion-code"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-plain text">debug1: Local version string SSH-2.0-OpenSSH_9.0
debug1: Remote protocol version 2.0, remote software version OpenSSH_6.6</code></pre><div class="notion-text notion-block-0f864f59aa89457da640836d9bf8af41">通过上述log可以看到客户端和服务端建立连接之后的 OpenSSH 版本号不一致</div><pre class="notion-code"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-plain text">debug1: Offering public key: /Users/jake/.ssh/id_rsa RSA SHA256:OyVqGeZW9HcURRFQBGBkTX5adtoQwZ9ibAEXgit___ agent
debug1: send_pubkey_test: no mutual signature algorithm</code></pre><div class="notion-text notion-block-9c72a9664a7a4cd4af20adbff9383852">确认支持公钥验证后将本地的 rsa 公钥发送到服务器，发现没有相互都能使用的签名算法，无法建立加密通讯，于是转而使用了备选方案 password</div><pre class="notion-code"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-plain text">debug2: we did not send a packet, disable method
debug3: authmethod_lookup password
debug3: remaining preferred: ,password
debug3: authmethod_is_enabled password
debug1: Next authentication method: password
git@gitlab.com&#x27;s password:</code></pre><div class="notion-text notion-block-5b799020309840ed99cbd67f474ddbb7">至于这个密码是什么密码实在是没有查到相关信息，尝试GitLab和RSA秘钥密码都不正确，有朋友了解的话指导下。</div><div class="notion-text notion-block-80eeeed359154c0c97b50e1840e1fe59"><b>根据以上信息基本可以确认是签名算法的兼容问题</b></div><div class="notion-text notion-block-b77e184005254723b8e786b9ebfde72a">查看OpenSSH的版本更新记录，发现OpenSSH在8.8版本禁用了使用SHA-1哈希签名作为RSA的签名算法。</div><div class="notion-text notion-block-bb7f746fabe049b79a02b3979df10a30"><a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://www.openssh.com/releasenotes.html"><em>Open</em></a><a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://www.openssh.com/releasenotes.html"><b>SSH</b></a><a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://www.openssh.com/releasenotes.html"> Release Notes</a></div><blockquote class="notion-quote notion-block-fad48bd21be04d52b6b770b85325abf5"><div>This release disables RSA signatures using the SHA-1 hash algorithm by default. This change has been made as the SHA-1 hash algorithm is cryptographically broken, and it is possible to create chosen-prefix hash collisions for &lt;USD$50K [1] 
For most users, this change should be invisible and there is no need to replace ssh-rsa keys. OpenSSH has supported RFC8332
RSA/SHA-256/512 signatures since release 7.2 and existing ssh-rsa keys will automatically use the stronger algorithm where possible.

Incompatibility is more likely when connecting to older SSH implementations that have not been upgraded or have not closely tracked improvements in the SSH protocol. For these cases, it may be necessary to selectively re-enable RSA/SHA1 to allow connection and/or user authentication via the HostkeyAlgorithms and PubkeyAcceptedAlgorithms options. For example, the following stanza in ~/.ssh/config will enable RSA/SHA1 for host and user authentication for a single destination host:

Host old-host
HostkeyAlgorithms +ssh-rsa
PubkeyAcceptedAlgorithms +ssh-rsa

We recommend enabling RSA/SHA1 only as a stopgap measure until legacy implementations can be upgraded or reconfigured with another key type
(such as ECDSA or Ed25519).</div></blockquote><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-ea7a5ce0b4604835b0932f20d2772145" data-id="ea7a5ce0b4604835b0932f20d2772145"><span><div id="ea7a5ce0b4604835b0932f20d2772145" class="notion-header-anchor"></div><a class="notion-hash-link" href="#ea7a5ce0b4604835b0932f20d2772145" title="解决方案"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">解决方案</span></span></h2><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-83ba8663b91d4f36a29d8f45f5c3d7a3" data-id="83ba8663b91d4f36a29d8f45f5c3d7a3"><span><div id="83ba8663b91d4f36a29d8f45f5c3d7a3" class="notion-header-anchor"></div><a class="notion-hash-link" href="#83ba8663b91d4f36a29d8f45f5c3d7a3" title="1. 添加兼容方案"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">1. 添加兼容方案</span></span></h3><div class="notion-text notion-block-e8e0d538f4994dd4bbe643c668e6140c">实践 openssh release note 中提供的 workaround</div><ol start="1" class="notion-list notion-list-numbered notion-block-039e10979d7a4b45a9fd83851ca68545"><li>在 <code class="notion-inline-code">~/.ssh </code> 目录下创建 config 文件，如果已经存在则忽略这步</li></ol><ol start="2" class="notion-list notion-list-numbered notion-block-3cd6d72a00374bdc91f5fc4e4b539a6c"><li>在 ~/.ssh/config 文件顶部添加</li></ol><pre class="notion-code"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-plain text">HostkeyAlgorithms +ssh-rsa
PubkeyAcceptedAlgorithms +ssh-rsa</code></pre><ol start="1" class="notion-list notion-list-numbered notion-block-233d73e8728d4276be85ca22dc335e54"><li>重新尝试就可以成功连接GitLab</li></ol><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-6dc4fb5375a74b289c61596e49b02e2a" data-id="6dc4fb5375a74b289c61596e49b02e2a"><span><div id="6dc4fb5375a74b289c61596e49b02e2a" class="notion-header-anchor"></div><a class="notion-hash-link" href="#6dc4fb5375a74b289c61596e49b02e2a" title="2. 替换加密算法（推荐）"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">2. 替换加密算法（推荐）</span></span></h3><div class="notion-text notion-block-572ffa59c1f742fa8486922554f77ee8">GitLab 中生成的非对称秘钥是</div><pre class="notion-code"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-plain text">ssh-keygen -o -t rsa -C &quot;your.email@example.com&quot; -b 4096</code></pre><div class="notion-text notion-block-1167cfc0ea894e81a9ff5141e8ed45e2">而 GitHub中建议生成非对称秘钥算法是  <code class="notion-inline-code">ed25519</code></div><pre class="notion-code"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-plain text">$ ssh-keygen -t ed25519 -C &quot;your_email@example.com&quot;</code></pre><div class="notion-text notion-block-96f81dcfbee74f7d8c45340f5e09b648">除非系统非常老旧不支持  <code class="notion-inline-code">ed25519</code>  算法才使用</div><pre class="notion-code"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-plain text">$ ssh-keygen -t rsa -b 4096 -C &quot;your_email@example.com&quot;</code></pre><div class="notion-text notion-block-9fa0eb409e514f90a8f5837c69fef28e">将 rsa 秘钥替换成 ed25519 秘钥添加到 GitLab ，通过验证可以正常通讯</div><pre class="notion-code"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-plain text">debug1: Offering public key: /Users/jake/.ssh/id_ed25519 ED25519 SHA256:CV5xWrRplYKEbPL500I8V4aBffTz9VsXWPIasxg9___
debug3: send packet: type 50
debug2: we sent a publickey packet, wait for reply
debug3: receive packet: type 60
debug1: Server accepts key: /Users/jake/.ssh/id_ed25519 ED25519 SHA256:CV5xWrRplYKEbPL500I8V4aBffTz9VsXWPIasxg9zHQ
debug3: sign_and_send_pubkey: using publickey with ED25519 SHA256:CV5xWrRplYKEbPL500I8V4aBffTz9VsXWPIasxg9___
debug3: sign_and_send_pubkey: signing using ssh-ed25519 SHA256:CV5xWrRplYKEbPL500I8V4aBffTz9VsXWPIasxg9___
debug3: send packet: type 50
debug3: receive packet: type 52</code></pre><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-5e11e798682a420c9b13c5c80460bb75" data-id="5e11e798682a420c9b13c5c80460bb75"><span><div id="5e11e798682a420c9b13c5c80460bb75" class="notion-header-anchor"></div><a class="notion-hash-link" href="#5e11e798682a420c9b13c5c80460bb75" title="实践"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><b>实践</b></span></span></h4><ol start="1" class="notion-list notion-list-numbered notion-block-cbdb1762d02b46c0823e9043a16d38a1"><li>生成 ed25519 秘钥</li></ol><pre class="notion-code"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-plain text">$ ssh-keygen -t ed25519 -C &quot;your_email@example.com&quot;</code></pre><ol start="1" class="notion-list notion-list-numbered notion-block-c5a4494488104963a8e4883958bef2b5"><li>在 .ssh 目录下复制 id_ed25519.pub中的内容，添加到GitLab</li></ol><pre class="notion-code"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-plain text">$ ssh -T git@gitlab.com
Welcome to GitLab, @jake!</code></pre><div class="notion-blank notion-block-63d6cce9f39b451bb011a0b6b8cf81ca"> </div><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-2d282b2c842d45618b34699fabb6c51f" data-id="2d282b2c842d45618b34699fabb6c51f"><span><div id="2d282b2c842d45618b34699fabb6c51f" class="notion-header-anchor"></div><a class="notion-hash-link" href="#2d282b2c842d45618b34699fabb6c51f" title="Reference"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">Reference</span></span></h4><div class="notion-row"><a target="_blank" rel="noopener noreferrer" class="notion-bookmark notion-block-f5ca5592728742e180fa7c203e137864" href="https://ikarus.sg/rsa-is-not-dead/"><div><div class="notion-bookmark-title">RSA keys are not deprecated; SHA-1 signature scheme is!</div><div class="notion-bookmark-description">Demystifying &quot;no mutual signature algorithm&quot; errors and the deprecation of &quot;ssh-rsa&quot; signature scheme in OpenSSH 8.8</div><div class="notion-bookmark-link"><div class="notion-bookmark-link-icon"><img src="https://ikarus.sg/content/images/size/w256h256/2020/07/Ikarus.sg-icon2-3.png" alt="RSA keys are not deprecated; SHA-1 signature scheme is!" loading="lazy" decoding="async"/></div><div class="notion-bookmark-link-text">https://ikarus.sg/rsa-is-not-dead/</div></div></div><div class="notion-bookmark-image"><img style="object-fit:cover" src="https://ikarus.sg/content/images/2022/07/ssh-rsa-deprecation.png" alt="RSA keys are not deprecated; SHA-1 signature scheme is!" loading="lazy" decoding="async"/></div></a></div></main></div>]]></content:encoded>
        </item>
    </channel>
</rss>